0
在 knockout js bind with datetimepicker gives an exception 延續我現在能夠使用的DateTimePicker與淘汰賽,但我無法使用相同的工具,我已經試過代碼被嵌入到下面的jsfiddle的時間選擇器選項,但編輯使用jQueryUI的的DateTimePicker與淘汰賽
在 knockout js bind with datetimepicker gives an exception 延續我現在能夠使用的DateTimePicker與淘汰賽,但我無法使用相同的工具,我已經試過代碼被嵌入到下面的jsfiddle的時間選擇器選項,但編輯使用jQueryUI的的DateTimePicker與淘汰賽
後拋出一個錯誤
<code>
http://jsfiddle.net/saqibshakil/scdET/
</code>
檢查控制檯看起來呼籲timepicker
getDate
不會返回實際Date
。
看起來您可以使用datetimepicker
成功調用它。所以,你的綁定看起來像:
ko.bindingHandlers.timepicker = {
init: function (element, valueAccessor, allBindingsAccessor) {
//initialize timepicker with some optional options
var options = allBindingsAccessor().timepickerOptions || {};
$(element).timepicker(options);
//handle the field changing
ko.utils.registerEventHandler(element, "change", function() {
var observable = valueAccessor();
observable($(element).datetimepicker("getDate"));
});
//handle disposal (if KO removes by the template binding)
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
$(element).timepicker("destroy");
});
},
//update the control when the view model changes
update: function (element, valueAccessor) {
var value = ko.utils.unwrapObservable(valueAccessor()),
current = $(element).datetimepicker("getDate");
if (value - current !== 0) {
$(element).datetimepicker("setDate", value);
}
}
};
你什麼錯誤? – Damien
你的小提琴長2000線。沒有人爲此付出時間。 – Tyrsius
Tyrius的小提琴是那麼長,因爲我使用了datetimepicker庫,因爲沒有cdn,因此我不得不將它粘貼到javascript中我會嘗試找到一個主機 –