jquery - JSON 控制台显示对象,但在使用 Vue.js 后给出未定义的属性错误

标签 jquery mysql json database vue.js

好吧,首先我从数据库中获取这种格式的 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/

相关文章:

javascript - 在字符串 Jquery/Javascript 中查找多个值

javascript - Jasmine.js v2.0.0 - TypeError : Cannot read property 'stopPropagation' of undefined

mysql - 在 mysql 中找不到表或列与选择和案例连接

python - MySQL 没有给出错误,但是没有一行被填充

mysql - 如何用MySQL存储3位小数

java - 如何使用 Jackson 库将 json 映射对象转换为对象数组

python json unicode - 我如何使用javascript进行评估

javascript - EasyUI 树形网格最初折叠全部

javascript - Bootstrap 下拉菜单总是想要强制 Accordion 风格

java - Jersey Web 应用程序类似 cron 的任务