Thursday, 15 April 2010

knockout.js - knockout dropdown -



knockout.js - knockout dropdown -

i having problem getting selected item of bound drop downwards list.

<p> group: <select data-bind="options: availablegroups, optionstext: 'name', optionsvalue: 'groupid', value: selectedgroup, optionscaption: 'choose...'"></select> </p> <p> visible have chosen <span data-bind="text: selectedgroup() ? selectedgroup().name: 'nothing'"></span> </p>

when take drop downwards list text of selection, not value. new knockout trying handle on this. i've created fiddle this.

http://jsfiddle.net/voam/fjrxn/

for original question @pete's reply right, since need preserve groupid value this (modified fiddle).

first selectedgroup property renamed selectedgroupid.

then new computed observable selectedgroup defined based on selectedgroupid:

self.selectedgroup = ko.computed(function () { (var = 0; < groups.length; i++) { if (groups[i].groupid == self.selectedgroupid()) homecoming groups[i]; } homecoming null; });

also var self = this defined

knockout.js

No comments:

Post a Comment