【发布时间】:2018-01-20 20:58:52
【问题描述】:
我试着打印一下
console.log(location_list.all_list[3]);
console.log(location_list.all_list);
但在 1 种情况下有“未定义”。 哪里不对?
更多代码:
var items = [];
$.getJSON( "js/location_list.json", function( data ) {
$.each( data, function( key, val ) {
items.push(key=val);
});
});
this.all_list = items;
结论: 此类赋值不能在“getJSON”中使用
this.all_list = items;
【问题讨论】:
-
location_list的值是多少? -
console.log(typeof location_list); // 对象
-
您只提供了 2 行代码并询问发生了什么,我们几乎没有回答
-
不,是 115、116 和 117 行