Is there a way to load json file using Backbone.js? -
i want load json file using backbone js , perform sorting , searching functions on data. can done using backbone. have started learning backbone kind of lost.
this can done using backbone. here's basic example of mu short suggested:
var collection = backbone.collection.extend({ url: 'http://echo.jsontest.com/key/value/one/two', initialize: function() { this.fetch(); this.listento(this, 'sync', this.sort); }, sort: function() { this.each(function(data) { document.write(data.get('key')); // should write "value" }); } }); var collection = new collection();
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.0/jquery.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js'></script> <script src='https://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.2.1/backbone-min.js'></script>
using backbone sorting , searching data particularly nice, since have access underscore's methods. see backbone collection docs , available underscore methods more info.
Comments
Post a Comment