Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dynamic 如何在SlickGrid中使用javascript添加行_Dynamic_Slickgrid - Fatal编程技术网

Dynamic 如何在SlickGrid中使用javascript添加行

Dynamic 如何在SlickGrid中使用javascript添加行,dynamic,slickgrid,Dynamic,Slickgrid,我正在尝试使用javascript将一行添加到我页面上光滑的网格中。我现在能够做到的方法是使用以下代码。我只是想知道是否有更好的方法来做同样的事情 .... //data is the array which was used to populate the SlickGrid data.push({name:'Finish scanning the slickgrid js', complete:false}); grid.setData(data); grid.render(); ..

我正在尝试使用javascript将一行添加到我页面上光滑的网格中。我现在能够做到的方法是使用以下代码。我只是想知道是否有更好的方法来做同样的事情

....

//data is the array which was used to populate the SlickGrid
data.push({name:'Finish scanning the slickgrid js', complete:false}); 
grid.setData(data);
grid.render();

....

这是首选的方式

data.push({...});
grid.updateRowCount();
grid.render();

调用.setData()强制网格重新呈现所有内容。通过调用updateRowCount(),可以通知网格行数已更改,它只需要呈现已添加或删除的内容

下面是我用来添加带有按钮的新行的内容

function add_new_row(){
  item = {"id": (Math.round(Math.random()*-10000))
  //you can add another fields to fill default data on Adding new row
  };
  data_view.insertItem(0, item);
}

这就是为什么我喜欢JavaScript的pass-by-reference:)