我正在尝试使用KnockOut,类似于此页面:http://knockoutjs.com/examples/cartEditor.html
但是,当与JQuery Mobile主题一起使用时 - 当您从“类别”下拉列表中选择一个项目时,它会在“产品”标题下添加一个下拉列表 - 但是刚刚添加的第二个下拉列表,没有移动样式应用
我在这里添加了一个小提琴:http://jsfiddle.net/mtait/adNuR/1927/ - 来演示。 我可以添加哪些内容将样式添加到新的下拉列表中?
function formatCurrency(value) {
return "$" + value.toFixed(2);
}
var CartLine = function() {
var self = this;
self.category = ko.observable();
self.product = ko.observable();
self.quantity = ko.observable(1);
self.subtotal = ko.computed(function() {
return self.product() ? self.product().price * parseInt("0" + self.quantity(), 10) : 0;
});
// Whenever the category changes, reset the product selection
self.category.subscribe(function() {
self.product(undefined);
});
};
var Cart = function() {
// Stores an array of lines, and from these, can work out the grandTotal
var self = this;
self.lines = ko.observableArray([new CartLine()]); // Put one line in by default
self.grandTotal = ko.computed(function() {
var total = 0;
$.each(self.lines(), function() { total += this.subtotal() })
return total;
});
// Operations
self.addLine = function() { self.lines.push(new CartLine()) };
self.removeLine = function(line) { self.lines.remove(line) };
self.save = function() {
var dataToSave = $.map(self.lines(), function(line) {
return line.product() ? {
productName: line.product().name,
quantity: line.quantity()
} : undefined
});
alert("Could now send this to server: " + JSON.stringify(dataToSave));
};
};
ko.applyBindings(new Cart());
谢谢,
标记
答案 0 :(得分:1)
我认为你需要一个客户绑定处理程序。
处理程序:
ko.bindingHandlers.jqmOptions = {
update: function (element, valueAccessor, allBindingsAccessor, context) {
ko.bindingHandlers.options.update(element, valueAccessor, allBindingsAccessor, context);
$(element).selectmenu();
$(element).selectmenu("refresh", true);
}
};
结合:
<select data-bind='jqmOptions : sampleProductCategories, optionsText: "name", optionsCaption: "Select...", value: category'> </select>