How to get model from server and display on view ?
I have already get the collection from server and displayed on view. Now I want to get details of single item when i pass Id to server. First I am getting collection and display in a grid. Now If someone clicks on gridview row then I passes id in url. I
want to get Model by passing this Id. What I do to get Model. I am getting Error - Uncaught TypeError: Cannot read property 'get' of undefined
************ Model start ************************
define([
'jquery',
'underscore',
'backbone'
], function ($, _, Backbone) {
var Order = Backbone.Model.extend({
idAttribute: "ID",
});
return Order;
});
************* Model End **************************
I have already get the collection from server and displayed on view
Dude, you got list of models(collection) from the server, so use the Collection.get(id) method to get the model details from the collection and display in the view for the model
http://backbonejs.org/#Collection-get
If your collections have a view, then your context for the click event is the collection itself, so you can use that method of collection object. use
console.log()
to your help to find which objects are passed on to your click event callback
Participant
760 Points
305 Posts
Can someone help me in backbone.js
Jun 04, 2014 03:10 PM|shwetamber|LINK
Hi All,
How to get model from server and display on view ?
I have already get the collection from server and displayed on view. Now I want to get details of single item when i pass Id to server. First I am getting collection and display in a grid. Now If someone clicks on gridview row then I passes id in url. I want to get Model by passing this Id. What I do to get Model. I am getting Error - Uncaught TypeError: Cannot read property 'get' of undefined
************ Model start ************************
************* Model End **************************
*************** View Start ***********************
*************** View End ************************
Can someone help me regarding this issue.
Thanks & Regards
shwetamber
jquery backbone SPA
Member
20 Points
11 Posts
Re: Can someone help me in backbone.js
Nov 08, 2014 01:31 AM|gokujames|LINK
Dude, you got list of models(collection) from the server, so use the Collection.get(id) method to get the model details from the collection and display in the view for the model
If your collections have a view, then your context for the click event is the collection itself, so you can use that method of collection object. use
to your help to find which objects are passed on to your click event callback
jquery backbone SPA