Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js validate collection

Backbone.js offers validation for models. But there is no a simple way to check all models in collection are valid. No .isValid property for collections.

I use a hack like this:

_.isEmpty(_.filter(myCollection.models, function(m) {return m.validationError;}))

Is there more optimized way to 'validate' collection?

like image 360
JuliaCesar Avatar asked Mar 28 '13 07:03

JuliaCesar


1 Answers

What about using some method?

var hasErrors = _.some(myCollection.models, function(m) {
    return m.validationError;
});
like image 76
dfsq Avatar answered Oct 06 '22 00:10

dfsq