0
app.Model.BrandModel = Backbone.Model.extend({
  idAttribute: 'brandId',
  defaults: {
    name : '',
    description : '',
    brandImage : '',
    user : '',
    showPro : false,
    proDescription : ''
  },
  url : function(){
    return '/rest/brands/' + brandId;
  }
 });

I can see from firebug that my my server is returning the following JSON response.Also the request is successful.

brandId "fc692c70-4096-11e3-a0f2-3c970e02b4ec"
name "Galeria"
user "940ee800-4090-11e3-80c0-3c970e02b4ec"
description "This is galeria"
brandImage "/brand-images/fc692c70-...3-a0f2-3c970e02b4ec.jpg"
proDescription ""
showPro false

I am calling like this.

var brandModel = new app.Model.BrandModel();
brandModel.fetch();

but my model is not getting populated and the values are still default one.

my controller

@RequestMapping(value = "/rest/brands/{brandId}",
       method = RequestMethod.GET,
       produces = "application/json")
@ResponseBody
public Brand getBrand(@PathVariable("brandId") String brandId, HttpServletResponse response) {
Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212

4 Answers4

0

I don't see where you are telling your code WHICH brandId to fetch... Have you tried this?

var brandModel = new app.Model.BrandModel({brandId: "fc692c70-4096-11e3-a0f2-3c970e02b4ec"});
brandModel.fetch();

More information: How do I fetch a single model in Backbone?

Community
  • 1
  • 1
David Fleeman
  • 2,588
  • 14
  • 17
0

fetch performs an asynchronous HTTP (Ajax) request, so I passeed fetch a success callback and now i am seeing the modal values.

brandModel.fetch({
   success: function(){
       console.log(brandModel.toJSON());  
   }
});
Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212
0

Should be:

app.Model.BrandModel = Backbone.Model.extend({
  idAttribute: 'brandId',
  urlRoot : '/rest/brands/',
  defaults: {
    name : '',
    description : '',
    brandImage : '',
    user : '',
    showPro : false,
    proDescription : ''
  }
 });

Then like @David mentioned:

var brandModel = new app.Model.BrandModel({brandId: "fc692c70-4096-11e3-a0f2-3c970e02b4ec"});
brandModel.fetch();
TYRONEMICHAEL
  • 4,174
  • 4
  • 30
  • 47
-1

Also return '/rest/brands/' + brandId; probably should be return '/rest/brands/' + this.get("brandId");

srdjans
  • 11
  • 3