0

I'm trying to use KnockOut, similar to this page: http://knockoutjs.com/examples/cartEditor.html

However, when used with the JQuery Mobile theme - when you select an item from the Category drop down, it then adds a drop down list under the Product heading - BUT the second dropdown just added, doesn't have the mobile styling applied.

I've added a Fiddle here: http://jsfiddle.net/mtait/adNuR/1927/ - to demonstrate. What can I add that will add the styling to the new drop down list?

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());

Thank you,

Mark

4

1 回答 1

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>

小提琴:http: //jsfiddle.net/adNuR/1942/

于 2013-08-27T13:38:48.693 回答