我不確定這裏有什麼問題,但是我們使用DatePicker從http://rniemeyer.github.com/knockout-kendo/web/DatePicker.html,當我們將項目發送回數組時,該字段沒有得到更新。 正如您將在下面的測試中看到的那樣,我們選擇的日期在我們發回時不會更新該項目。 任何幫助,非常感謝。 謝謝使用Knockout-Kendo不更新observableArray上的項目的值
演示測試 http://s7.postimage.org/68n30bd6z/knockoutjs_knockout_kendo.gif
的jsfiddle http://jsfiddle.net/DiegoVieira/epqUb/4/
JS
var data =
[
{
"name": "Diego",
"birthday": "01/01/1984"
},
{
"name": "Franciele",
"birthday": "01/05/1983"
}
];
var person = function() {
this.id = ko.observable(0);
this.name = ko.observable();
this.birthday = ko.observable();
}
function viewModel() {
var self = this;
self.people = ko.observableArray(data);
self.personData = ko.observable(new person());
self.selectedPerson = ko.observable();
self.addPerson = function() {
var item = ko.toJS(new person());
item.id = getRandomNumber();
self.people.push(item);
self.selectedPerson(item);
}
self.editPerson = function(item)
{
self.selectedPerson(item);
}
self.savePerson = function(item)
{
var index = self.people.indexOf(item);
self.people.remove(item);
self.people.splice(index, 0, item);
self.selectedPerson(null);
}
self.deletePerson = function(item)
{
var index = self.people.indexOf(item);
self.people.remove(item);
}
}
ko.applyBindings(new viewModel());
function getRandomNumber(min, max) {
if (typeof min === 'undefined')
min = 10000000;
if (typeof max === 'undefined')
max = 99999999;
return min + Math.floor(Math.random() * (max - min + 1));
}
HTML
<div data-bind="with: $root.selectedPerson">
<table border="1" cellpadding="1" cellspacing="1">
<tr>
<td>Name:</td>
<td><input data-bind="value: name" /></td>
</tr>
<tr>
<td>Birthday:</td>
<td><input data-bind="kendoDatePicker: birthday" /></td>
</tr>
<tr>
<td colspan="2"><button data-bind="click: $root.savePerson">Save</button></td>
</tr>
</table>
</div>
<button data-bind="click: $root.addPerson">Add Person</button>
<ul data-bind="foreach: $root.people">
<li><span data-bind="html: name"></span> (<span data-bind="html: birthday"></span>) <button data-bind="click: $root.editPerson">Edit</button> <button data-bind="click: $root.deletePerson">Delete</button></li>
</ul>