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

Iterate through a json object based on the value of an array in mootools

本文关键字:迭代 json 对象 mootools 数组 基于      更新时间:2023-09-26

我有这段代码:

['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的有效对象?我不确定正确的术语,所以任何帮助也将是一个奖励:)

如何:

['design','finish','grills'].each(function(type) {
    this.json[type].each(function(obj, index) {
        console.log(obj);
    });
}.bind(this));

当前你的代码正试图找到一个名为type的属性,而不是变量包含的键。

我明白了:

['design','finish','grills'].each(function(type) {
    this.json[type].each(function(obj, index) {
        console.log(obj);
    });
}.bind(this));