淘汰赛剑道电网与批量编辑不更新视图模型(Knockout-Kendo Grid with batch

2019-08-17 14:26发布

我不知道什么是错我的执行,但我不能,如果我使用编辑KendoUI电网用淘汰赛剑道让我的视图模型更新。 如果我改变了一些特定的表字段和记录的视图模型也不会得到任何更新。

<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/

什么是这种行为的原因是什么?

提前致谢。

Answer 1:

数据源,以KO集成不是此刻浑然一体。 因为,剑道控件不知道如何处理直接观测,KO-剑道提供的数据对小部件的“干净”版本。 这意味着更新的数据未在视图模型数据自动表示。

我希望探索与淘汰赛(可能是KO数据源)数据源更好的集成,其中自动同步将更新视图模型。 这是后话,希望能在短期内发生。

现在,有一些可以用来从网格中的数据同步到您的VM模式。

示例: http://jsfiddle.net/rniemeyer/73mjn/

下面是一个示例视图模型:

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-Kendo Grid with batch editing doesn't update the viewmodel