gpt4 book ai didi

knockout.js - 具有批量编辑功能的 Knockout-Kendo Grid 不会更新 View 模型

转载 作者:行者123 更新时间:2023-12-03 13:09:36 25 4
gpt4 key购买 nike

我不知道我的实现有什么问题,但如果我将可编辑的 KendoUI 网格与 Knockout-Kendo 一起使用,我将无法更新我的 View 模型。如果我更改某些特定的表字段并记录 View 模型,它将不会获得任何更新。

<button data-bind="click: log">Log ViewModel</button>
<div id="gr" data-bind="kendoGrid: options"></div>

var pStyleHeader_ViewModel = function() {
this.options = {
data: ko.observableArray([{ StyleNo : ko.observable("1BA0012"),
Description : ko.observable(""),
StyleType : ko.observable("10"),
DueDate : ko.observable(new Date("2012-10-31T00:00:00+02:00"))}]),
sortable: true,
columns: [{"field":"StyleNo","title":"Style No"},{"field":"Description","title":"Description"},{"field":"StyleType","title":"Style Type","editor":StyleTypeDropDownEditor,"values":StyleTypeValues},{"field":"DueDate","title":"Due Date","type":"date","format":"{0:MM/dd/yyyy}"}],
editable: true,
selectable: true,
pageable: { pageSize: 5 }
};

ko.applyBindings(new pStyleHeader_ViewModel());

您可以在此处查看示例:http://jsfiddle.net/aleksanderson/hd5c8/

这种行为的原因是什么?

提前致谢。

最佳答案

数据源到 KO 的集成目前不是无缝的。由于 Kendo 小部件不知道如何直接处理 observables,因此 ko-kendo 向小部件提供了数据的“干净”版本。这意味着对该数据的更新不会自动显示在 View 模型数据中。

我希望探索与 Knockout(可能是 KO 数据源)更好的数据源集成,其中 autoSync 将更新 View 模型。这是有希望在短期内发生的事情。

目前,您可以使用一些模式将数据从网格同步到您的虚拟机。

样本:http://jsfiddle.net/rniemeyer/73mjn/

这是一个示例 View 模型:

var Person = function(data) {
this.first = ko.observable();
this.last = ko.observable();

this.full = ko.computed(this.getFull, this);

//initialize it the first time
this.initialize(data);
};

ko.utils.extend(Person.prototype, {
getFull: function() {
return this.first() + ' ' + this.last();
},
//can be called at anytime to initialize/update data
initialize: function(data) {
this.first(data.first);
this.last(data.last);
}
});

var ViewModel = function() {
this.people = ko.observableArray([
new Person({ first: "Bob", last: "Smith" }),
new Person({ first: "Doug", last: "Jones" }),
new Person({ first: "Sally", last: "Green" })
]);

//store a reference to the widget, so we can get at the modified data
this.people.grid = ko.observable();

//reconcile the grid data with the view model data
this.syncData = function() {
var people = this.people() || [],
gridPeople = this.people.grid().dataSource.data() || [],
person, gridPerson, i, length;

//loop through the grid's people and update each vm person
for (i = 0, length = gridPeople.length; i < length; i++) {
gridPerson = gridPeople[i];
person = people[i];

//add a new person, if necessary
if (!person) {
people.push(new Person(gridPerson));
} else {
person.initialize(gridPerson);
}
}
};
};

关于knockout.js - 具有批量编辑功能的 Knockout-Kendo Grid 不会更新 View 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15409741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com