ModelBinder CollectionBinder Ex2
HTML
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.3/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.modelbinder/0.1.3/Backbone.ModelBinder-min.js"></script>
<br>
Testing actions:
<br>
<input type="button" id="createModel" value="Create Model"/>
<input type="button" id="removeModel" value="Remove Last Model"/>
<input type="button" id="updateModel" value="Update Last Model's Phone"/>
<input type="button" id="resetCollection" value="Reset Collection"/>
<br>
<br>
View content:<hr>
<div id="viewContent">
<table>
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
JavaScript
// Backbone.CollectionBinder v1.1.0
// (c) 2015 Bart Wood
// Distributed Under MIT License
!function(e){"function"==typeof define&&define.amd?define(["underscore","jquery","backbone","Backbone.ModelBinder"],e):"undefined"!=typeof module&&module.exports?module.exports=e(require("underscore"),require("jquery"),require("backbone")):e(_,$,Backbone)}(function(e,t,i){if(!i)throw"Please include Backbone.js before Backbone.ModelBinder.js";if(!i.ModelBinder)throw"Please include Backbone.ModelBinder.js before Backbone.CollectionBinder.js";i.CollectionBinder=function(t,n){if(e.bindAll.apply(e,[this].concat(e.functions(this))),this._elManagers={},this._elManagerFactory=t,!this._elManagerFactory)throw"elManagerFactory must be defined.";this._elManagerFactory.trigger=this.trigger,this._options=e.extend({},i.CollectionBinder.options,n)},i.CollectionBinder.SetOptions=function(e){i.CollectionBinder.options=e},i.CollectionBinder.VERSION="1.1.0",e.extend(i.CollectionBinder.prototype,i.Events,{bind:function(e,t){if(this.unbind(),!e)throw"collection must be defined";if(!t)throw"parentEl must be defined";this._collection=e,this._elManagerFactory._setParentEl(t),this._onCollectionReset(),this._collection.on("add",this._onCollectionAdd,this),this._collection.on("remove",this._onCollectionRemove,this),this._collection.on("reset",this._onCollectionReset,this),this._collection.on("sort",this._onCollectionSort,this)},unbind:function(){void 0!==this._collection&&(this._collection.off("add",this._onCollectionAdd),this._collection.off("remove",this._onCollectionRemove),this._collection.off("reset",this._onCollectionReset),this._collection.off("sort",this._onCollectionSort)),this._removeAllElManagers()},getManagerForEl:function(t){var i,n,o=e.values(this._elManagers);for(i=0;i<o.length;i++)if(n=o[i],n.isElContained(t))return n;return void 0},getManagerForModel:function(t){return this._elManagers[e.isObject(t)?t.cid:t]},_onCollectionAdd:function(e,t,i){var...