Ever have those days that just seem to be working against you? Yeah, today was that day for me. Ultimately though, I was the victor (at least in this instance) against my Javascript model that said NO NO NO, I kept trying and succeeded where I wondered if I should even continue trying or move a separate way.

After a bit of playing I figured it out… essentially, when binding to a select list, you have two forms of output that can be obtained… an output of an individual property on your model, or the complete model itself. Below is my example and the solution I found, for those of you looking to do a similar thing.

 http://jsfiddle.net/eEGxV/36/

That’s one thing I love about KO, always a way to make my job easier (once i figure it out! lol)
Anyways, in this example, I have an item that contains 3 properties (obviously there can be more), but only a single one is bound to the "text" attribute via "optionsText"… if you don’t specify a property to be returned for a value,( e.g. I could have made id, or quantityAvail the return type here), but this limits the return value to a single parameter. If you do not specify the optionsValue attribute for your select, it returns the entire object, meaning, you get everything.
Ultimately it depends what you are trying to accomplish, but I found this method very helpful for my complex and I figured I would share!

-Haddy
Keep Moving Forward

Advertisements