昨天经过大量的帮助后,我采用了演示车示例,并将其应用到我的应用程序中(搜索B& B房间)。
这个想法是,你从(1)房间类型中选择 - 然后填充(2)占用者 - 当你从(2)占用者中选择时,它填充(3)Number Reqd
问题是,一旦选择了占用者数量,我就无法将移动样式添加到新添加的下拉列表中:
这里有一个工作小提琴:http://jsfiddle.net/mtait/g8cQz/5/
在@Dan的帮助下 - 通过添加jqmOptions: sampleProductCategories
,他将样式应用于Occupants下拉列表:
<td>
<select data-bind='jqmOptions: sampleProductCategories, options: $root.RoomCategories, optionsText: "TypeName", optionsCaption: "Select...", value: category'></select>
</td>
<td data-bind="with: category">
<select data-bind='jqmOptions: sampleProductCategories, options: Occs, optionsText: "occdesc2", optionsCaption: "Select...", value: $parent.occupancy'></select>
</td>
<td class='quantity' data-bind="with: category">
<select data-bind="visible: $parent.occupancy, options: ko.utils.range(0, TypeCount), value: $parent.quantity"></select>
</td>
ko.bindingHandlers.jqmOptions = {
update: function (element, valueAccessor, allBindingsAccessor, context) {
ko.bindingHandlers.options.update(element, valueAccessor, allBindingsAccessor, context);
$(element).selectmenu();
$(element).selectmenu("refresh", true);
}
};
我需要添加什么来获取Number Required下拉列表或Occupants下拉列表,以便在选择Occupants时将样式添加到数字reqd?
谢谢,
标记
答案 0 :(得分:0)
将初始jQuery mobile select移动到init方法,也使用applyBindingsToNode而不是在选项绑定上手动调用update
ko.bindingHandlers.jqmOptions = {
init: function(element, valueAccessor, allBindingsAccessor, context) {
ko.applyBindingsToNode(element, { options: valueAccessor() }, context);
$(element).selectmenu();
},
update: function (element, valueAccessor, allBindingsAccessor, context) {
$(element).selectmenu("refresh", true);
}
};