3

実装の何が問題になっているのかわかりませんが、Knockout-Kendoで編集可能な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/

そのような行動の理由は何ですか?

前もって感謝します。

4

1 に答える 1

4

dataSourceからKOへの統合は、現時点ではシームレスではありません。剣道ウィジェットはオブザーバブルを直接処理する方法を知らないため、ko-kendoは「クリーンな」バージョンのデータをウィジェットに提供します。これは、そのデータの更新がビューモデルデータに自動的に表示されないことを意味します。

autoSyncがビューモデルを更新するKnockout(おそらくKOデータソース)とのより良いdataSource統合を探求しようとしています。これは、短期的にはうまくいけば起こることです。

今のところ、グリッドから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);   
            }
        }
    };
};
于 2013-03-14T14:03:18.700 に答える