Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Master/Detail with Knockout

Tags:

knockout.js

I have an observableArray of Knockout models. I want to be able to display detail for the one that's selected and keep the textboxes etc. bound to the model for that Knockout item, possible?

like image 306
user1166905 Avatar asked Feb 19 '23 13:02

user1166905


1 Answers

You'll want to create an observableArray to store the items, and bind them to some html to show them. Then use a click binding to (or some other event) to trap which one the user selected. Then in that event you can set the selected item.

Here is a fiddle that demonstrates this.

http://jsfiddle.net/johnpapa/3DPvU/

The HTML could like look this:

<ul data-bind="foreach: people">
<li data-bind="text:name, click:$parent.selectPerson"></li>
</ul>

<div data-bind="with:selectedPerson">
<span data-bind="text:id"></span>
<input data-bind="value:name"/>
<input data-bind="value:country"/>
</div>​
like image 68
John Papa Avatar answered Feb 27 '23 09:02

John Papa