Saturday, 15 March 2014

javascript - Backbone Collection get Object -



javascript - Backbone Collection get Object -

not versed in backbone, understand if don't explain completely.

i have collection trying retrieve. here illustration of json:

{ "id" : "section-one", "href" : "section-one-baseball", "divisions" : [ { "name": "orioles", "division" : "al east" } ] }

my problem can't figure out how sections name. when set in console:

baseballteams.models[0].get("divisions")

i object name , division. if set in:

baseballteams.models[0].get("divisions.name")

i undefined. matter more not sure how retrieve name of object, , why looking help please. give thanks in advance.

try this.

baseballteams.models[0].get("divisions")[0].name

1.baseballteams.models[0].get("divisions") homecoming following

[ { "name": "orioles", "division" : "al east" } ]

[] meaning array

2.baseballteams.models[0].get("divisions")[0] homecoming following

{ "name": "orioles", "division" : "al east" }

{} meaning object

then can value want below

baseballteams.models[0].get("divisions")[0].name

or

baseballteams.models[0].get("divisions")[0]["name"]

javascript backbone.js

No comments:

Post a Comment