knockout.js - KnockoutJS, passing field of object in the array as <input> value -
is there possibility pass field of object in observable array value of input? example, need similar this:
<input type="text" data-bind="value: persons()[0].name"/>
so edit field of object in array.
it works (just tested out of curiosity on 1 of projects)
however, "persons" array knockout observable array. there chance binding operation fails because "persons" array null or not populated @ least 1 object when start web application.
if want that, suggest first check in binding persons array populated, example:
<input type="text" data-bind="value: persons().length ? persons()[0].name : null"/>
you ensure binding operation not crash, regardless of initialization state of array.
Comments
Post a Comment