简体   繁体   English

将多个项目(如数组)添加到现有Kendo UI DataSource

[英]Add Multiple Items Such as an Array to Existing Kendo UI DataSource

I've been working on this for a few hours and cannot manage to find a way to get it to work properly. 我已经在这个工作了几个小时,无法找到一种方法让它正常工作。 I'm looking for the proper way to add the contents of an array to an existing Kendo UI DataSource. 我正在寻找将数组内容添加到现有Kendo UI DataSource的正确方法。 Basically I have 4 SharePoint lists and I am fetching data using DataJS from each list. 基本上我有4个SharePoint列表,我从每个列表中使用DataJS获取数据。 I want to then display the items in a Kendo GridView but I don't want to add the items using a for statement and the add() method. 我想在Kendo GridView中显示项目,但我不想使用for语句和add()方法添加项目。 I have tried using the add() method on the array directly but all this does is add the array as an object itself to the DataSource and, of course, that is not the intended behavior. 我已经尝试直接在数组上使用add()方法,但所有这一切都是将数组作为对象本身添加到DataSource,当然,这不是预期的行为。 I also attempted using dataSource.data.concat() but received the error: 我也尝试使用dataSource.data.concat()但收到错误:

Object doesn't support property or method 'concat' 对象不支持属性或方法'concat'

Lets say that you have the new data in an array called newData . 假设您在一个名为newData的数组中有新数据。 You can use: 您可以使用:

var newData = [
    { ... },
    { ... },
    { ... }
];

$.merge(newData, datasource._pristine);
datasource.data(newData);

The above solution did not work for me. 上述解决方案对我不起作用。 Suggested by a Telerik admin is the method below: Telerik管理员建议使用以下方法:

var vm = kendo.observable({
  data: new kendo.data.ObservableArray([])
});

vm.data.push.apply(vm.data, [ 1, 2, 3]);

This way results in one render for bound widgets. 这种方式导致绑定小部件的一个渲染。 Found here: http://www.telerik.com/forums/passing-array-to-observablearray-push 在此处找到: http//www.telerik.com/forums/passing-array-to-observablearray-push

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM