| Wijmo Team Member | Mike.Griffin posted on May 26, 2012 at 3:53 pm Can you show us how to bind a combobox to some json data, it would be great if you had one page that bound each control to a viewmodel. I’m stuck on this and cannot figure it out. | |
| Wijmo Team Member | Chris Bannon posted on May 26, 2012 at 4:38 pm Check out the demos for binding each widget here http://wijmo.com/demo/explore/#knockout|overview Click the view source button to see the code. These samples are all in the download too. | Answer |
| Wijmo Team Member | Mike.Griffin posted on May 26, 2012 at 4:56 pm I feel stupid, I didn’t even notice the bar on the right that allowed for me to see demo’s for all the controls, thanks so much !! | Answer |
| Wijmo Team Member | Mike.Griffin posted on May 26, 2012 at 4:59 pm Okay, quick follow up. If we bind to a combobox do our properties have to be named label and value. I want to display Name and Id, are we hard locked into label/value property names? | Answer |
| Wijmo Team Member | Mike.Griffin posted on May 26, 2012 at 6:23 pm Interesting, when I called ko.applyBindings() it was taking 45 seconds. I figured out what was going on. I’m using entityspaces.js, a javascript orm. It has lazyload properties. It seems like your binding code might be looping over every property/method and invoking them during databinding. The ko.wijmo.customBindingFactory is calling ko.toJS() which is causing everything to lazy load. In fact, knockout isn’t very smart, it will hang on circular references. I’ll go ahead and regenerate and remove the lazy loaded properties because then it’s very fast. Just be aware that ko.toJS() invokes every method and property, and our lazy load methods are functions that hit the database, just a heads up. I’m building a huge application with wijmo and knockout so I’ll really be putting it through the paces … | Answer |
| Wijmo Team Member | Mike.Griffin posted on May 28, 2012 at 11:49 am Here’s a cool little helper routine for binding to wijmo controls that want a label and value. It works correctly if the data is observable or not observable.
var wijmo_binders = {};
wijmo_binders.getLabelValueBindings = function (collection, label, value) {
var coll, idx, item, list = [];
coll = ko.utils.unwrapObservable(collection);
for (idx = 0; idx < coll.length; idx = idx + 1) {
item = coll[idx];
list.push({
"label": ko.utils.unwrapObservable(item[label]),
"value": ko.utils.unwrapObservable(item[value])
});
}
return list;
};
I use it like this .. list = wijmo_binders.getLabelValueBindings(coll, "Name", "TableId"); where "list" is bound as the data: to a combobox. I imagine I'll have more wijmo_binders which is why I created it that way. Routines could be built into the controls like this, for instance.
wijlist: { listItems: list, label: 'Name', value: 'TableId', selectionMode: 'multiple' }">
And internally wijmo use the routine above to pull the label/name out of the collection (list) passed in, just a thought. Lovin me some wijmo + ko man, good work ! | Answer |
Tagged: knockout
This topic has 2 voices, contains 5 replies, and was last updated by Mike.Griffin 361 days ago.
You must be logged in to reply to this topic.