我正在尝试使用类似于此页面的 KnockOut:http://knockoutjs.com/examples/cartEditor.html
但是,当与 JQuery Mobile 主题一起使用时 - 当您从类别下拉列表中选择一个元素时,它会在产品标题下添加一个下拉列表 - 但是刚刚添加的第二个下拉列表没有移动样式应用。
我在这里添加了一个 fiddle :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());
谢谢,
标记
最佳答案
我认为您需要一个客户绑定(bind)处理程序。
处理程序:
ko.bindingHandlers.jqmOptions = {
update: function (element, valueAccessor, allBindingsAccessor, context) {
ko.bindingHandlers.options.update(element, valueAccessor, allBindingsAccessor, context);
$(element).selectmenu();
$(element).selectmenu("refresh", true);
}
};
绑定(bind):
<select data-bind='jqmOptions : sampleProductCategories, optionsText: "name", optionsCaption: "Select...", value: category'> </select>
fiddle :http://jsfiddle.net/adNuR/1942/
关于javascript - KnockoutJS 新添加的元素没有样式表中的任何样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18442745/