基于mootools中数组的值迭代json对象

时间:2011-12-08 12:11:30

标签: javascript object mootools

我有这段代码:

['design','finish','grills'].each(function(type) {

    this.json.type.each(function(obj, index) {
        console.log(obj);
    });

}.bind(this));

并收到此错误:

this.json.type is undefined

如何让type成为each的有效内容? 我不确定正确的术语,所以对此的任何帮助也将是一个奖励:)

2 个答案:

答案 0 :(得分:0)

我明白了:

['design','finish','grills'].each(function(type) {

    this.json[type].each(function(obj, index) {
        console.log(obj);
    });

}.bind(this));

答案 1 :(得分:0)

怎么样:

['design','finish','grills'].each(function(type) {

    this.json[type].each(function(obj, index) {
        console.log(obj);
    });

}.bind(this));

目前,您的代码正在尝试查找名为type的属性,而不是该变量包含的密钥。