2
var mappingSetting = {
'user' : {
create: function(options.data){
options.data.isActive = options.data.isActive == 1 ? 'Yes' : 'No';
options.data.startDate = $.datepicker.format('dd/MM/yy', options.data.startDate)
return options.data;
}
}
};
var viewModel = {};
$.ajax({
url: '/api/users/GetAll',
.....
success: functions (data) {
viewModel = ko.mapping.fromJS(data, mappingSetting);
ko.applyBindings(viewModel);
},
});
$("#savebtn").click(function(){
var dataToSave = ko.toJS(viewModel);
// ajax call to save
});
AJAX結果有沒有辦法控制ko.toJS/ko.toJSON?
[{username: 'users1', isActive:1, startDate:'2001-03-22T00:00:00CET'}, {username: 'users2', isActive:0, startDate:'2008-03-22T00:00:00CET'}]
我必須表明是/否isActive的基礎上,但同時節省我不得不更改回0/1
我有許多領域,也日期(當地文化格式)。