问题
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