filtering for max value in collection in backbone.js

丶灬走出姿态 提交于 2019-12-10 18:53:58

问题


I have a collection of models having structure:

{"name":"xyz","company":"abc","recNumber":"M34/14-15/23"}

I need to get that specific model from this collection whose recNumber is highest(based on number after last slash). I guess it can be done with .filter from underscore but don't know what will be the exact construct in this case.


回答1:


try this;

model = collection.max(function(m){
  return _.last(m.get('recNumber').split('/'));
});

collection.max() Returns the maximum value in list.

_.last(array) Returns the last element of an array.

jsfiddle here



来源:https://stackoverflow.com/questions/15247111/filtering-for-max-value-in-collection-in-backbone-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!