Question

How can I display the following JSON object in Backbone View Template which I got with console.log?

Object {207: "402", 208: "400", 209: "402", 210: "0", 211: "0", 212: "50", 301: "401", 302: "400"} 

I did use <% =207 %> and <% =208 %> in order to get value "402" and "400", but it didn't work.

Thank you very much for your help!

(edited)

Hi Vitaliy, are you still there? In this case I got from console.log, how can I print the value of "timestamp" and also "101"?

Object {timestamp: "2013-06-26T17:36:03+0530", values: Object} timestamp: "2013-06-26T17:36:03+0530" values: Object 101: "81" 102: "1500" 201: "49" proto: Object

Thank you in advance!

Was it helpful?

Solution

You cannot use numbers as object keys. This is syntax error. Modify your object keys like that {"key_207": "402", ...}

Also to print result you should use <%= key_207 %> instead of <% =key_207 %>

The best way to fix this issue is to modify server response on the server side.

But also you can try do this (I'm not sure if it will work in all browsers):

var res = {207: "402", 208: "400"};
console.log(res[207]); // -> 402

So you need to pass your model to template inside some object and acces to key in the way above:

__template__({data:this.model.toJSON()})

And then:

<%= data[207] %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top