I have implemented it in the past as a method on can.Model.List. Say you wanted to be able to update a list of recipes:
- Recipe = can.Model({
- findAll: "/recipes"
- },{})
- Recipe.List = can.Model.List({
- update: function( props ) {
- if( props ){
- this.each(function(item){ item.attr(props) })
- }
- var data = this.serialize(),
- self = this;
- return $.ajax({
- url: "/recipes",
- type: "PUT",
- data: data,
- success: function(data){
- // might be used to update the isntances data like:
- // self[i].attr(data)
- },
- dataType: "json"
- })
- }
- })
Use it like:
- Recipe.findAll({}, function(recipes){
- recipes.update({tasty: true}).then(function(){
- })
- })