rest - backbone.js won't fetch data and populate the collection -
i have setup: require.js + backbone.js, populate collection using fetch function of backbone
orders.js(collection)
define([ 'underscore', 'backbone', 'models/item' ], function(_, backbone, item){ var orders = backbone.collection.extend({ model: item, url: 'json/items', initialize: function(){ }, }); return orders = new orders(); });
orders.js(views)
define([ 'jquery', 'underscore', 'backbone', 'collections/orders', 'models/item', 'text!templates/orders.tpl', ], function($, _, backbone, orders, item, orderstemplate){ var ordersview = backbone.view.extend({ model: orders, template: _.template(orderstemplate), initialize: function() { _.bindall(this); orders.fetch({ success: function() { console.log(orders.models) }}); }, }); return ordersview; });
orders.fetch won't populate collection, though browser detects xhr json/items:
i tried solution backbone.js + rest. collection not populated after fetch() still won't work. there way can fetch data , populate automatically collection? or missing something?
ps: sorry brute code posting...
edit: success callback on fetch won't json/items called xhr on browser
edit: update code on order.js, removed store param
edit: appreciate if can on url http://mindanaojobs.net/backbone/ , inspect in it, jsfiddle seems little bit tricky
does xhr response contain array of objects? if there kind of object wrapper like
{items: [{...}, {...}]}
then need implement parse
method accordingly.
yes, looked @ code , need in orders collection:
parse: function (response) { return response.items;}
Comments
Post a Comment