2014-07-21 43 views
0

我想顯式地設置過濾器來填充KendoUI列表視圖, 按本link我這樣做,爲數據源顯式地設置過濾器KendoUI

 $(function() { 
     var model = { 
      items:ko.observableArray([]) 
     } 
     var dataSource = new kendo.data.DataSource({ 
      serverFiltering: true, 
      pageSize: 20, serverPaging: true, 
      schema: { data: function (data) { return data.Items; }, total: function (data) { return data.Count; } }, 
      type: 'odata', 
      change: function() { 
       var items = this.data(); 
       console.log(items); 
       model.items.removeAll(); 
       for (var x=0;x<items.length;x++) { 
        model.items.push(items[x]); 
       } 
      }, 
      transport: { 
       read: { 
        url: "/api/my/thumbnail/", 
        dataType: "json", 
       } 
      }, 
     }); 


     dataSource._filter = [{ field: "Id", operator: "eq", value: 149 }]; 
     ko.applyBindings(model, document.getElementById("thumbnailListView")); 
     dataSource.read(); 

    }); 
</script> 

這是我在數據源獲取,

ct.extend.init {options: Object, _map: Object, _prefetch: Object, _data: ct.extend.init[0], _pristineData: Array[0]…} 
_aggregate: undefined 
_changeHandler: function() { 
_data: ct.extend.init[0] 
_destroyed: Array[0] 
_events: Object 
_filter: Array[1] 
0: Object 
field: "Id" 
operator: "eq" 
value: 149 
__proto__: Object 
length: 1 
__proto__: Array[0] 
_group: Array[0] 
length: 0 
__proto__: Array[0] 
_map: Object 
_page: 1 
_pageSize: 20 
_prefetch: Object 
_pristineData: Array[0] 
_pristineTotal: 0 
_ranges: Array[0] 
_sort: undefined 
_total: undefined 
_view: Array[0] 
data: function (e){var n=this;return e===t?n._data:(n._data=this._observe(e),n._pristineData=e.slice(0),n._ranges=[],n._addRange(n._data),n._total=n._data.length,n._pristineTotal=n._total,n._process(n._data),t)} 
options: Object 
reader: dt.extend.init 
table: null 
transport: dt.extend.init 
__proto__: n.extend.r 

但dataSource.read(),我得到這個錯誤:'未捕獲的類型錯誤:無法讀取未定義的屬性'長度'。

+0

您是否嘗試使用'dataSource.filter(...)'以編程方式設置過濾器?查看文檔[here](http://docs.telerik.com/kendo-ui/api/framework/datasource#methods-filter) – OnaBai

回答