好吧,首先我从数据库中获取这种格式的 json 对象...
{
"position": "slider",
"size": "large",
"type": "slider",
"params":[{
"id": "10",
"title": "testfea",
"extension": "jpg",
"type": "image",
"path": "\/image\/1.jpg"
}]
}
我使用 grep 进行一些过滤...
// get all the large widgets
var largeWidgets = $.grep($widgetsData, function(e){
var farr = $.parseJSON(e.params);
return farr.size == 'large';
});
// get all the widgets where the position equals the live one
var filteredByPos = $.grep(largeWidgets, function(e){
var farr = $.parseJSON(e.params);
return farr.position == that.position;
});
我正在使用 vue.js,因此我将其分配给数据对象...
this.fullWidget = filteredByPos;
var json = fullWidget[0].params;
console.log(json.params[0]);
所以首先它记录对象,但是当我尝试访问属性时,它给了我这个错误:
Uncaught TypeError: Cannot read property 'params' of undefined
在这个位置
var json = $.parseJSON(JSON.stringify(that.fullWidget[0].params));
特别是[index].property
that.fullWidget[0].params
最佳答案
要么是因为 fullWidget
不是数组(或空数组),要么是因为您使用的是 fullWidget
而不是 this.fullWidget
。
关于jquery - JSON 控制台显示对象,但在使用 Vue.js 后给出未定义的属性错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31242667/