2014-02-21 37 views

回答

0

您更好地使用這個post ...優秀的指南中描述的骨幹方式的行爲: )

+0

達格海爾特直接與attributes hash工作。感謝您的文章,我一定會讀它。然而,我的主要問題是如何迭代模型的屬性。模型有屬性屬性,它獲得了模型的屬性,但我認爲是JSON對象 – Mefhisto1

3

您可以使用collection.each遍歷模型和_.each在模型上的按鍵以應用功能:

collection.each(function(model) { 
    _.each(model.keys(), function(attribute) { 
     console.log(attribute, model.get(attribute)); 
    }); 
}); 

並演示http://jsfiddle.net/6YP9W/

或者如果你喜歡

collection.each(function(model) { 
    _.each(model.attributes, function(val, attribute) { 
     console.log(attribute, val); 
    }); 
}); 

http://jsfiddle.net/6YP9W/1/

相關問題