JS代码,报错提示push()未定义
想把json数据从本地读取后,存入数组。但是push()总报错:UncaughtTypeError:Cannotreadproperty'push'ofundefined...
想把json数据从本地读取后,存入数组。但是push()总报错:Uncaught TypeError: Cannot read property 'push' of undefined
代码如下
var buildVOList = function(data) {
//深拷贝
//var voList = util.getCache('voList');
var voList = [];
for (var i = 0, l = data.length; i < l; i++) {
var el = data[i];
var obj = new WifiVO({
stime: el.stime,
macadd: el.macadd,
vendor: el.vendor,
VlanID: el.VlanID,
protocolName: el.protocolName,
sessionTime: el.sessionTime,
Avg: el.Avg,
Bytesent: el.Bytesent,
ByteReceived: el.ByteReceived,
RSSI: el.RSSI,
building: el.building,
room: el.room
});
//console.log(obj);
voList.push(obj);
}
return voList;
}
function initApp(){
initDataTree();
}
function initDataTree(callback) {
//传入数据
$.getJSON('data/test.json', function(data) {
//console.log(data);
buildVOList(data);
callback && callback();
});
}
initApp();
json的数据是这样:
[{"associationTime":1488786392000,"clientMacAdd":"84:11:9e:5c:46:4f","vendor":"Unknown","vlanID":825,"protocol":"802.11n(2.4GHz)","sessionDuration":"5min 5sec","avgThroughput":"14.3","byteSent":160259,"byteReceived":387198,"RSSI":-44,"building":"5","room":"302"}, 展开
代码如下
var buildVOList = function(data) {
//深拷贝
//var voList = util.getCache('voList');
var voList = [];
for (var i = 0, l = data.length; i < l; i++) {
var el = data[i];
var obj = new WifiVO({
stime: el.stime,
macadd: el.macadd,
vendor: el.vendor,
VlanID: el.VlanID,
protocolName: el.protocolName,
sessionTime: el.sessionTime,
Avg: el.Avg,
Bytesent: el.Bytesent,
ByteReceived: el.ByteReceived,
RSSI: el.RSSI,
building: el.building,
room: el.room
});
//console.log(obj);
voList.push(obj);
}
return voList;
}
function initApp(){
initDataTree();
}
function initDataTree(callback) {
//传入数据
$.getJSON('data/test.json', function(data) {
//console.log(data);
buildVOList(data);
callback && callback();
});
}
initApp();
json的数据是这样:
[{"associationTime":1488786392000,"clientMacAdd":"84:11:9e:5c:46:4f","vendor":"Unknown","vlanID":825,"protocol":"802.11n(2.4GHz)","sessionDuration":"5min 5sec","avgThroughput":"14.3","byteSent":160259,"byteReceived":387198,"RSSI":-44,"building":"5","room":"302"}, 展开
1个回答
2017-04-10 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
var buildVOList = function(data) {
//深拷贝
//var voList = util.getCache('voList');
var voList = [];
for (var i = 0, l = data.length; i < l; i++) {
var el = data[i];
var obj = new WifiVO({
stime: el.stime,
macadd: el.macadd,
vendor: el.vendor,
VlanID: el.VlanID,
protocolName: el.protocolName,
sessionTime: el.sessionTime,
Avg: el.Avg,
Bytesent: el.Bytesent,
ByteReceived: el.ByteReceived,
RSSI: el.RSSI,
building: el.building,
room: el.room
});
//console.log(obj);
voList.push(obj);
}
return voList;
}
function initApp(){
initDataTree();
}
function initDataTree(callback) {
//传入数据
$.getJSON('data/test.json', function(data) {
//console.log(data);
buildVOList(data);
callback && callback();
});
}
links 是节点数组中的索引,应该从0开始。从1开始,因此最高的数字' t存在,并给你这个错误。
//深拷贝
//var voList = util.getCache('voList');
var voList = [];
for (var i = 0, l = data.length; i < l; i++) {
var el = data[i];
var obj = new WifiVO({
stime: el.stime,
macadd: el.macadd,
vendor: el.vendor,
VlanID: el.VlanID,
protocolName: el.protocolName,
sessionTime: el.sessionTime,
Avg: el.Avg,
Bytesent: el.Bytesent,
ByteReceived: el.ByteReceived,
RSSI: el.RSSI,
building: el.building,
room: el.room
});
//console.log(obj);
voList.push(obj);
}
return voList;
}
function initApp(){
initDataTree();
}
function initDataTree(callback) {
//传入数据
$.getJSON('data/test.json', function(data) {
//console.log(data);
buildVOList(data);
callback && callback();
});
}
links 是节点数组中的索引,应该从0开始。从1开始,因此最高的数字' t存在,并给你这个错误。
追问
那这个应该怎么修改呢?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询