Windows 8 WinJS.Binding.List-键值为';找不到
我有一个WinRT/javaScript应用程序,我在其中使用列表。作为测试,我得到了以下代码:Windows 8 WinJS.Binding.List-键值为';找不到,windows-8,windows-runtime,windows-store-apps,winjs,Windows 8,Windows Runtime,Windows Store Apps,Winjs,我有一个WinRT/javaScript应用程序,我在其中使用列表。作为测试,我得到了以下代码: var testList = new WinJS.Binding.List(); var item = { key: "mykey", value: "hello", value2: "world" }; testList.push(item); var foundItem = testList.getItemFromKey("mykey"); 我希望能够使用提供的钥匙
var testList = new WinJS.Binding.List();
var item = {
key: "mykey",
value: "hello",
value2: "world"
};
testList.push(item);
var foundItem = testList.getItemFromKey("mykey");
我希望能够使用提供的钥匙找到我的物品;但是,foundItem
总是返回未定义项。我的列表的设置和使用中是否有错误
另外,当我在调试时检查列表时,我可以看到我推送的项的键是“1”,而不是“mykey”。您推送的是列表中对象的值,该键在内部被指定为递增整数值。如果在项目中打开WindowsLibraryforJavaScript1.0参考中的
base.js
,您将看到push
的以下实现
注意对this的调用。\u assignKey()。此值将在处理程序中返回给您
您正在推送的是列表中对象的值,该键在内部被指定为递增整数值。如果在项目中打开WindowsLibraryforJavaScript1.0参考中的
base.js
,您将看到push
的以下实现
注意对this的调用。\u assignKey()。此值将在处理程序中返回给您
push: function (value) {
/// <signature helpKeyword="WinJS.Binding.List.push">
/// <summary locid="WinJS.Binding.List.push">
/// Appends new element(s) to a list, and returns the new length of the list.
/// </summary>
/// <param name="value" type="Object" parameterArray="true" locid="WinJS.Binding.List.push_p:value">The element to insert at the end of the list.</param>
/// <returns type="Number" integer="true" locid="WinJS.Binding.List.push_returnValue">The new length of the list.</returns>
/// </signature>
this._initializeKeys();
var length = arguments.length;
for (var i = 0; i < length; i++) {
var item = arguments[i];
if (this._binding) {
item = WinJS.Binding.as(item);
}
var key = this._assignKey();
this._keys.push(key);
if (this._data) {
this._modifyingData++;
try {
this._data.push(arguments[i])
} finally {
this._modifyingData--;
}
}
this._keyMap[key] = { handle: key, key: key, data: item };
this._notifyItemInserted(key, this._keys.length - 1, item);
}
return this.length;
},
testList.oniteminserted = function (e) {
var newKey = e.detail.key;
};