Backbone.js BackboneJS-使用.max从模型中获取特定值
所以我有这个:Backbone.js BackboneJS-使用.max从模型中获取特定值,backbone.js,Backbone.js,所以我有这个: var competitionModel = new Competition.CompetitionModel(); competitionModel.contest_id = this.contest_id; this.insertView('.comp', new Competition.View({model: competitionModel})); competitionModel.fetch(); 到目前为止,模型及其(所选)值已显示在中 现在我想从同一个模型中得到
var competitionModel = new Competition.CompetitionModel();
competitionModel.contest_id = this.contest_id;
this.insertView('.comp', new Competition.View({model: competitionModel}));
competitionModel.fetch();
到目前为止,模型及其(所选)值已显示在
中
现在我想从同一个模型中得到一个特定的值,在这种情况下,profile\u image
,它必须是模型中的最大值。我读了一些关于.max()
-方法的文章,但我不知道如何使用它
我有这样的结构:
<div class="image"></div>
<div class="comp"></div>
1) 可能吗?2) 我能用同样的方法吗?像this.insertView('.image',blablab)
那么,有谁能帮我一下吗?好的,从你的评论来看,这个房产是一系列的东西 您不能使用主干
max
(仅适用于集合),但可以使用下划线max
(它们是一样的,最后,前者是后者的包装器,但我们不必深入讨论细节)。您可以看到集合.max()
正在运行
您应该能够执行以下操作:
var max = _.max(competitionModel.get("property"));
var max = _(competitionModel.get("property")).max(function (e) { ... });
最终,您可以传递一个函数来转换值:
var max = _.max(competitionModel.get("property"), function (element) {
// element is a single item in the list, return a number here.
});
或者,您也可以使用下划线包装,如下所示:
var max = _.max(competitionModel.get("property"));
var max = _(competitionModel.get("property")).max(function (e) { ... });
有关
max()
的更多信息,请参见。max of what?它是一个集合还是一个模型,它的属性是一个事物列表?我想要模型中属性的最大值