Here is what I still have:
var Item = Backbone.Model.extend({ defaults: { id: 0, pid: 0, t: null, c: null }, idAttribute: 'RootNode_', // what should this be ??? url: 'page.php' }); var ItemList = Backbone.Collection.extend({ model: Item, url: 'page.php', parse: function(data) { alert(JSON.stringify(data)); // returns a list of json objects, but does nothing with them ??? } }); var ItemView = Backbone.View.extend({ initialize: function() { this.list = new ItemList(); this.list.bind('all', this.render, this); this.list.fetch(); }, render: function() { // access this.list ??? } }); var view = new ItemView();
Current (expected) json response:
{ "RootElem_0":{"Id":1,"Pid":1,"T":"Test","C":"Blue"}, "RootElem_1":{"Id":2,"Pid":1,"T":"Test","C":"Red"}, "RootElem_2":{"Id":3,"Pid":1,"T":"Test2","C":"Money"} }
This successfully checks page.php , and the backend acts on $_SERVER['REQUEST_METHOD'] and returns the requested information, however I do not know why the collection is not full.
In the parse the ItemList function ItemList it correctly shows me all the output, but it does nothing with it.
I left some comments in the code for more precise questions, but the main question is: why is the collection not filled with explicitly received data ?