datepicker值中隐藏的天数不再被传递(Knockout)

时间:2014-03-19 12:36:44

标签: javascript knockout.js datepicker

我正在修改使用knockout的现有代码,我不确定它是如何工作的但是经过一些测试后,似乎被推送的数据绑定仅在选择了一天时适用于datepicker。我希望隐藏这些日子,并在“完成”时将其绑定。单击按钮上的按钮showButtonPanel。

有人可以帮忙吗?

这是我的模特

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

1 个答案:

答案 0 :(得分:0)

我完全不理解我的解决方案,但现在是:

我没有更改淘汰赛代码:

    $('.datepicker').datepicker({  //the elements MUST have the class 'datepicker'
    changeMonth: true,  
    changeYear: true,
    maxDate: '-4Y',
    yearRange: "1900:<?php echo date('Y'); ?>", //for selecting from 1900 to now
    dateFormat: 'mm/yy',
    showButtonPanel: true,

    onClose: function(dateText, inst){
        var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
        var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
        $(this).datepicker('setDate', new Date(year, month, 1));
        $(this).change(); //this seems to update the model
    },      
});