[{"pk": 1, "model": "social.thing", "fields": {"content": "this is good", "visible": true, "user": 1, "parent": [2], "title": "hat i like"}}, {"pk": 5, "model": "social.thing", "fields": {"content": "because must be good", "visible": true, "user": 1, "parent": [2], "title": "another good thing"}}]
Is there possibility to append to some DOM element single value from one of dictionary from my list. For example, how to select "pk":1 from this list?
You can access the first object in the main Array by index
[0], then access the value of thepkproperty via.pk.Example: http://jsfiddle.net/FBjuW/
…or you could loop over the outer Array to get the
pkvalue at each index.Example: http://jsfiddle.net/FBjuW/1/
I don’t know what DOM element you’re talking about, but you can append the resulting value to your element if you need.
EDIT:
If you’re doing a DOM selection, and need to append the
pkvalue per result found, you could do this:This uses the
append()[docs] method and passes a function to it. The return value is the value that gets appended.The
iparameter represents the index number of the current matched element during the iteration.