Javascript 主干-集合中更大的模型属性
伴侣 我试图从一个主干集合中获得更大的属性,该集合包含了所有模型 例如:Javascript 主干-集合中更大的模型属性,javascript,backbone.js,Javascript,Backbone.js,伴侣 我试图从一个主干集合中获得更大的属性,该集合包含了所有模型 例如: App.Models.Example = Backbone.Model.extend({ defaults: { total: 0, created_at: '0000-00-00', updated_at: '0000-00-00' } }); App.Collections.Examples = Backbone.Collection.exte
App.Models.Example = Backbone.Model.extend({
defaults: {
total: 0,
created_at: '0000-00-00',
updated_at: '0000-00-00'
}
});
App.Collections.Examples = Backbone.Collection.extend({
model: App.Models.Example,
url: 'examples'
});
var examples = new App.Collections.Examples();
examples.sync();
我需要得到的是,在现场创建的更大的_
我怎么能这么做
谢谢 我想您是在要求从集合中创建了最新的
的集合中检索模型。是吗
如果是,请使用下划线max函数,如下所示:
var mostRecentDateModel = examples.max(function(model){
return model.get("created_at");
});
// this prints the most recent date that you are after
console.log(mostRecentDateModel.get("created_at"));
您需要记住,如果模型的created_at
属性不是JavaScript日期(可能是字符串),那么max
函数可能不会返回您期望的结果。因此,确保它确实是一个日期和/或将其转换为一个日期可能是值得的
希望这有帮助