2011-12-08 35 views
0

我有這樣一段代碼:迭代通過一個JSON對象,基於在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? 我不知道正確的術語,所以任何幫助,這也將是一個獎金:)

回答

0

如何:

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

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

}.bind(this)); 

目前你的代碼試圖找到一個名爲type的屬性,而不是變量包含的關鍵字。

0

我想通了:

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

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

}.bind(this));