【发布时间】:2013-08-26 11:12:04
【问题描述】:
我正在尝试使用 KnockOut,类似于此页面:http://knockoutjs.com/examples/cartEditor.html
但是,当与 JQuery Mobile 主题一起使用时 - 当您从 Category 下拉列表中选择一个项目时,它会在 Product 标题下添加一个下拉列表 - 但是刚刚添加的第二个下拉列表没有移动样式已申请。
我在这里添加了一个 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());
谢谢,
标记
【问题讨论】:
-
This question 可能对你有帮助。
-
嗨 Jereon - 谢谢 - 这也是我的帖子之一,但我无法让 .trigger 工作 - 我已添加到上面的示例中。
-
抱歉,我没有注意到另一个问题也是你的问题。
-
我试图再看看你的问题,但我无法让你的代码工作。请参阅here,我已尝试将您的代码复制到其中。请通过删除与问题无关的所有内容来清理您的代码(它们使外人很难阅读您的问题),并添加重现问题所需的任何代码。理想情况下,您问题中的代码绝对是最少的,可以立即显示问题的小提琴环境中删除。
-
嗨@Jeroen - 我在这里添加了一个小提琴:jsfiddle.net/mtait/adNuR/1926 - 如果您单击添加产品,您可以看到添加的新下拉列表,没有移动样式。谢谢。
标签: javascript jquery css jquery-mobile knockout.js