I have some things I need to store as observables in my app. I've tried creating separate veiwmodels but when I bind them it clears the others. So I'm just going to post what my basic data layout is and see if anyone is willing to suggest a way to define the viewmodels...
- Search Results
- Result Name
- Result Type
- Items
- Item Name
- Type
- properties
- Property Name
- Property Value
- More?
The biggest trick is that I'm trying to bind each item to a dynamically created element like so:
$("<div/>", { //create new div
class: "itemView", //add css class
id: name, //set ID to item name (may change to array location later?)
"data-bind": "template: { name: 'tmplItemView' }"
}).appendTo("body").draggable(); //append to the body and make it draggable
items[numItems] = new item();
ko.applyBindings(items[numItems],
document.getElementById('#' + name));
I'm trying to use something like this: http://www.knockmeout.net/2012/05/quick-tip-skip-binding.html but from what I gather it's better to define your view models as functions, so that's what I'm doing and I'm not sure where to go from here.
Here is a nonfunctional fiddle of everything I have so far: http://jsfiddle.net/MDNAJ/
Again, it lists all the results and you can click a result and get a popup with the correct info, but the search results disappear.