Last active
December 12, 2015 10:38
-
-
Save saadtazi/4760030 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
can.Model.List.prototype.filter = function(cb) { | |
var res = []; | |
debugger; | |
this.each(function(amodel, pos, models) { | |
var ares = cb.call(amodel, pos, models); | |
if (ares === true) {res.push(amodel)} | |
}); | |
return res | |
} | |
// usage | |
var MyModel = can.Model({}); | |
var myInst = new MyModel.List([{attr1: 1, att2: 2}, {attr1: 'one', att2: 'two'}]); | |
t = myInst.filter(function(pos, list) { | |
// this = an item in list - should return true (not just a non-falsy value) if you want to keep that item | |
if (pos % 2 == 0) {return true;} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment