knockout.js - How do I access an object by index in a knockout observablearray? -
i have observable array:
var myobservablearray = ko.observablearray([ { name: "car", price: "9999" }, { name: "shoes", price: "20" }, { name: "paper", price: "1" } ]); i'm trying access price of first item in array.
<div data-bind="text: myobservablearray()[0]"></div> displays:
[object object] i've tried:
<div data-bind="text: myobservablearray()[0].price"></div> but returns null.
what's correct syntax doing this?
edit: fixed copy , paste error pointed out below.
other using wrong property name, developerexampledata instead of myobservablearray, code fine.
here working fiddle
Comments
Post a Comment