我想明确地设置一个过滤器来填充 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() 上,我收到此错误:'Uncaught TypeError: Cannot read property 'length' of undefined'。