javascript - Backbone - remove last model in Collection, but only by filter -
this.keyscollection.pop();
removing last 1 pretty simple, i'd ideally (pseudo solution):
this.keyscollection.pop({ type: 'foo' });
and remove last matching model collection. possible?
edit:
went -
const models = this.where({ type: 'foo' }); const model = models[models.length - 1]; this.remove(model);
pop gets last element , calls remove on result, backbone source
pop: function(options) { var model = this.at(this.length - 1); this.remove(model, options); return model; },
since that's case can use where models match filter , pass last model results remove yourself.
var matchingmodels = this.where({type: 'foo'}); this.remove(matchingmodels[matchingmodels.length - 1]);
Comments
Post a Comment