0

I have these lines:

console.log(JSON.stringify(this.model.attributes));
console.log(this.model.get('name'));

And this is the output:

"{"name":"ffg","key":"1c277f82-f093-d359-4cfb-febe4614a3b1"}"
""

I'm starting with Backbone. Any ideas why the object is in the attributes but it returns empty with the get method??

EDIT:

This shouldn't affect answers, but I'm working with Phone Gap.

The 2 console.log are lines next to each other.

EDIT 2:

var temp = _(this.model.attributes).clone();
console.log(JSON.stringify(temp));
console.log(temp.name);

This logs:

{"name":"ss","questions":[],"order":0,"key":"5c35c304-4863-02c0-4d18-101c655aa4ae"}
""
Community
  • 1
  • 1
davibq
  • 1,089
  • 11
  • 31
  • 1
    What does `console.log(_(this.model.attributes).clone())` have to say? – mu is too short Jun 27 '14 at 02:04
  • 2
    are you logging these 2 statements one after the other in the same function scope ? Might be a stupid question, but just want to make sure you dont take for granted that the model is not modified between logging events. – QuantumLicht Jun 27 '14 at 02:24
  • something funky is going on with some part of your code that you haven't shared. come up with the smalled possible repro steps for the problem and we can help. otherwise, it's just guessing at what random things you could have screwed up :) – Robert Levy Jun 27 '14 at 03:18
  • The 2 console lines are next to each other. This console.log(_(this.model.attributes).clone()) logs: {"name":"dav","questions":[],"order":0,"key":"42214b09-9c2b-c63e-e4e5-915c9367f60d"} Please check the edits – davibq Jun 27 '14 at 18:12

2 Answers2

1

I would consider logging this.model and inspecting the object into a browser (e.g. Chrome or Firefox) then look into the attributes property of the object. Make sure that the name property is defined as you intended. Also, please make sure that no event is triggered that could modify your model object.

QuantumLicht
  • 2,103
  • 3
  • 23
  • 32
0

When you fetch model, try set this yourModel.fetch({async: false})

zpawn
  • 1
  • 1