如何将数据添加到SlickGrid DataView?

时间:2012-01-19 20:50:54

标签: javascript jquery jquery-plugins slickgrid

我正在尝试使用带有SlickGrid jQuery插件的DataView follow the simple example。但是,我无法弄清楚如何将数据添加到DataView。

这是来源的相关部分:

var dataView;
var grid;
var data = [];
...
$(function() {
    // prepare the data
    for (var i=0; i<50000; i++) {
        var d = (data[i] = {});
        d["id"] = "id_" + i;
        ... add data to d
    }
    dataView = new Slick.Data.DataView();
    grid = new Slick.Grid("#myGrid", dataView, columns, options);

所以现在设置了网格,但data如何绑定它?我无法在the example中找到添加它的位置,因此我不知道如何添加自己的数据。

谢谢!

2 个答案:

答案 0 :(得分:5)

在示例的源代码中进一步查看 - 您将找到以下行:

// initialize the model after all the events have been hooked up
dataView.beginUpdate();
dataView.setItems(data);

这就是dataView的项目被设置为data []数组中的数据。

答案 1 :(得分:-1)

我今天刚下载了一个新版本。我的节目

  $(function () {
var data = [];
for (var i = 1; i < 12; i++) {
  data[i] = {
    title: "Task " + i,
    duration: "5 days",
    percentComplete: Math.round(Math.random() * 100),
    start: "01/01/2009",
    finish: "01/05/2009",
    effortDriven: (i % 5 == 0)
  };
}

grid = new Slick.Grid("#myGrid", data, columns, options);

})

数据阵列是你坚持数据。

相关问题