我想明确设置一个用于填充KendoUI列表视图的过滤器, 按照link我这样做了,
$(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>
这是我在dataSource中得到的,
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()上,我收到此错误:'未捕获的TypeError:无法读取未定义'的属性'length'。
答案 0 :(得分:1)
不确定这会有所帮助,但您可以尝试这种方法 -
dataSource.data()
dataSource.at(1)
datasource.view()
dataSource.data().toJSON()