我有这段代码:
['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
的有效内容?
我不确定正确的术语,所以对此的任何帮助也将是一个奖励:)
答案 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
的属性,而不是该变量包含的密钥。