@Artem Vyshni akovの答えは正しいです。しかし、あなたがIEのポリフィルを探しての代わりに、それをサポートするブラウザでHTML5の番号入力を交換している場合は、この方法を試してください。
ko.bindingHandlers.spinner = {
init: function (element, valueAccessor, allBindingsAccessor) {
if (Modernizr.inputtypes.number) {
ko.bindingHandlers.value.init.apply(null, arguments);
} else {
//initialize spinner with some optional options
var options = allBindingsAccessor().spinnerOptions || {};
$(element).spinner(options);
//handle the field changing
$(element).on("spinstop", function() {
var observable = valueAccessor();
observable($(element).spinner("value"));
});
//handle disposal
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$(element).off("spinstop");
$(element).spinner("destroy");
});
}
},
update: function (element, valueAccessor, allBindingsAccessor) {
if (Modernizr.inputtypes.number) {
ko.bindingHandlers.value.update.apply(null, arguments);
} else {
var value = ko.utils.unwrapObservable(valueAccessor());
var disable = allBindingsAccessor().disable;
if (typeof disable !== "undefined") {
$(element).spinner((disable) ? "disable" : "enable");
}
var current = $(element).spinner("value");
if (value !== current) {
$(element).spinner("value", value);
}
}
}
};
function Order(name, price, vat, number) {
var self = this;
self.Name = ko.observable(name);
self.Price = ko.observable(price);
self.VAT = ko.observable(vat);
self.Number = ko.observable(number);
self.Final = ko.computed(function() {
return (self.Price() + self.VAT()) * self.Number();
});
}
function ViewModel() {
var self = this;
self.orders = ko.observableArray();
self.removeOrder = function(item) {
self.orders.remove(item);
};
self.save = function() {
alert(ko.toJSON(self));
};
}
var viewModel = new ViewModel();
viewModel.orders.push(new Order("Sugar", 100, 15, 3));
viewModel.orders.push(new Order("Salt", 200, 25, 4));
viewModel.orders.push(new Order("Milk", 200, 35, 1));
ko.applyBindings(viewModel);
ここに完全なフィドル:http://jsfiddle.net/mberkom/pCJWc/
どのフィールドにスピナーを適用しますか? –