修改主干集合

时间:2013-07-15 10:44:22

标签: backbone.js for-loop underscore.js

我有一个包含模型集合的集合。在提交给服务器之前,我必须获取每个模型并设置更多属性。

如何使用骨干网做这件事。?

更新:

这就是我试图打印模型的情况,如果它打印出来想尝试使用模型的set属性,但是它给了我uncaught typeerror cannot call method 'each' of undefined

covertInvestmentJournal:function(){
            this.investmentTransactionsCollection.each(function(model){
                  console.log(model); 
                });
        }

1 个答案:

答案 0 :(得分:0)

这就是我解决问题的方法:

for (var i = 0, l = investmentTransactionsCollection.length; i < l; i++) {
                investmentTransactionsCollection.models[i].set({securityName:$('#security-name').val()});
                investmentTransactionsCollection.models[i].set({valueDate:DateUtils.formatAsYMD($('#value-date'))});
                investmentTransactionsCollection.models[i].set({adjustmentType:$('#adjustment-type').val()});
                investmentTransactionsCollection.models[i].set({assetClass:$('#assetclass').val()});
                investmentTransactionsCollection.models[i].set({currency:$('#currency').val()});
            }