2016-09-09 5 views
0

私のアプリケーションには、剣道ツリーリストと剣道コンボボックスがあります。 TreeListのDataSourceをComboBoxに使用することもできます。これが可能であれば、同じクエリを2度実行する必要がなくなります。剣道データソースをComboBoxとTreeListの間で共有する

これは、私のTreeListがCRUD操作用のトランスポートを使用することによって、さらに複雑になります。私の共有データソースの

例:

 var sharedDataSource = new kendo.data.DataSource({ 
      transport: { 
       read: function (e) { 
        webService.getData(arg1, arg2).then(function (response) { 
         e.success(response.data); 
        }, function (response) { 
         console.log(response); 
        }); 
       } 
      } 
     }); 

     sharedDataSource.read(); 

私TreeListの搬送部:

transport: { 
    read: function (e) { 
     e.success(sharedDataSource);//sharedDataSource has NO data here. That's the problem 
    } 
} 

コンボボックス:

  $("#comboBox").width(250).kendoComboBox({ 
       dataTextField: "name", 
       dataValueField: "id", 
       dataSource: sharedDataSource//The comboBox is launched via a click after the page loads and DOES have data here 
      }); 

答えて

0

DataSource.read()は非同期メソッドです。 TreeListが初期化されているとき、データはまだロードされていないので、空になります。

約束を解決してread方法を使用しても解決する必要があります

sharedDataSource.read().then(function() { 
    // TreeList init 

    // ComboBox init 
}); 

TreeListは、ページングやグループ化、(一度にすべてのツリーアイテムをロードすると仮定)を持っていないので、あなたがデータを抽出し、望ましくない避けるためにDataSource.view() methodを使用することができますリモートリクエスト。

// TreeList and ComboBox transports 

transport: { 
    read: function (e) { 
     e.success(sharedDataSource.view()); 
    } 
} 

道場のデモ:http://dojo.telerik.com/@msagi/EnEnI(偽のリモート呼び出しで)

関連する問題