我的目标是根据特定条件将 JSON 对象添加到数组中,然后将其用于构造 WINJSList。使用 array.push 方法后,我真的很难访问列表或数组的元素。我想访问这些元素以确保我正确地进行了添加。任何帮助将不胜感激。我有以下代码
var names_Array = new Array;
var names_List = new WinJS.Binding.List(names_Array);
if (condition) {
if (condition) {
names_List.push({ name: "Joe Dowling", image: "image/Joe Dowling.png", ClientID: "1234" });
}
else if (condition) {
names_List.push({ name: "Esteban Flamenco ", image: "image/Esteban Flamenco.png", ClientID: "6666" });
}
else if (condition) {
names_List.push({ name: "Plain Jane ", image: "image/Plain Jane.png", ClientID: "0000" });
}
console.log(names_Array);
console.log(names_Array[0]);
console.log(names_List);
console.log(names_List[0]);
我也试过:
var names_Array = new Array; if (condition) {
if (condition) {
names_Array.push({ name: "Joe Dowling", image: "image/Joe Dowling.png", ClientID: "1234" });
}
else if (condition) {
names_Array.push({ name: "Esteban Flamenco ", image: "image/Esteban Flamenco.png", ClientID: "6666" });
}
else if (condition) {
names_Array.push({ name: "Plain Jane ", image: "image/Plain Jane.png", ClientID: "0000" });
}
var names_List = new WinJS.Binding.List(names_Array);
在控制台中,我要么得到 undefined 要么 [object object]