0
我正在修改現有的代碼使用淘汰賽,我真的不知道它是如何工作的,但經過一些測試,似乎數據綁定被推送只適用於datepicker當選擇一天時。我想隱藏日子,並在datepicker showButtonPanel上單擊「完成」按鈕時將其綁定。在datepicker值中隱藏的日子不再通過(敲除)
任何人都可以幫忙嗎?
這裏是我的模型
var viewModel = function(previousaddress){
var self = this;
var action;
var id;
self.PREVIOUS_ADDRESS=ko.observable('');
self.PREVIOUS_POSTCODE=ko.observable('');
self.FROM_DATE=ko.observable();
self.TO_DATE=ko.observable();
self.addresses=ko.observableArray(previousaddress);
self.addPreviousAddress = function(formElement) {
var newPreviousAddress = new PreviousAddress(
self.PREVIOUS_ADDRESS(),
self.PREVIOUS_POSTCODE(),
self.FROM_DATE(),
self.TO_DATE()
);
var validate_function;
if(self.action == 'new'){
validate_function = function(data){
data = $.parseJSON(data);
if(data){
newPreviousAddress.ID = data.insert_id;
self.addresses.push(newPreviousAddress);
}else{
//error
}
};
}else if(self.action == 'update'){
newPreviousAddress.ID = self.id;
validate_function = function(data){
data = $.parseJSON(data);
if(data){
newPreviousAddress.ID = data.update_id;
self.addresses.remove(function(item) {return item.ID == data.update_id});
self.addresses.push(newPreviousAddress);
}else{
//error
}
};
}
validate(newPreviousAddress, validate_function, 'previous-address-add', self.action);
$('#myModal').modal('hide');
self.PREVIOUS_ADDRESS('');
self.PREVIOUS_POSTCODE('');
self.FROM_DATE();
self.TO_DATE();
};
self.updateAction = function(){
self.action = 'new';
};
self.editPreviousAddress = function (care) {
self.action = 'update';
self.id = care.ID;
$('#myModal').modal('show');
self.PREVIOUS_ADDRESS(care.PREVIOUS_ADDRESS);
self.PREVIOUS_POSTCODE(care.PREVIOUS_POSTCODE);
self.FROM_DATE(care.FROM_DATE);
self.TO_DATE(care.TO_DATE);
};
};
使用模糊/聚焦事件觸發你的模型更新? –
看來,$(this).change()也起作用,元素必須具有類.datepicker,否則其他任何東西都會將其分解。 – liamfriel