我想用knockout.js來使用這個jquery color picker。我寫了自定義帶綁定處理程序綁定colorpicker輸入控件與我的viewModel顏色值。jquery顏色選擇器綁定處理程序創建多個div
這裏是結合處理程序代碼:
ko.bindingHandlers.colorPicker = {
init: function (element, valueAccessor, allBindingsAccessor) {
//initialize datepicker with some optional options
var options = allBindingsAccessor().colorPickerOptions || {};
$(element).colorPicker(options);
//handle the field changing
ko.utils.registerEventHandler(element, "change", function() {
var observable = valueAccessor();
observable($(element).colorPicker("value"));
});
//handle disposal (if KO removes by the template binding)
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$(element).colorPicker("destroy");
});
},
update: function (element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor());
$(element).colorPicker("value", value);
}
和HTML:
<input type="text" data-bind="colorPicker: newEvent().color, colorPickerOptions: { value:newEvent().color }"/>
問題是,當我改變顏色它創建的多個div每當我改變顏色時,如圖在圖像中。在我的代碼
誰能請identiy什麼問題?
什麼是'newEvent'?你能提供一個小提琴這個問題的細節嗎? – jimmym715