大家好,我正在使用 backgrid 来渲染我的表格。我不知道如何在列中添加元素。有人可以告诉我该怎么做吗?
最佳答案
查看此处的文档/api后:http://backgridjs.com/ 您可以通过以下方式实现这一目标:
// Since 0.3.0, you can listen to the `backgrid:next` to see if a cell
// movement was out of bound, if yes, you can insert a new row.
// A movement is only out of bound when the user was trying to go beyond
// the last row.
grid.collection.listenTo("backgrid:next", function (i, j, outOfBound) {
// this will add a row using the collection's model too
if (outOfBound) grid.collection.add({});
});
您可以使用以下代码添加行/元素:grid.collection.add({});
编辑
因此 Backgrid.js 使用 Backbone.js 通过以下方法添加一行: insertRow( model, collection, options)
( http://wyuenho.github.io/backgrid/api/index.html#!/api/Backgrid.Body )
直接调用时,它接受一个模型或模型数组以及一个选项哈希,就像 Backbone.Collection#add 一样。并代表出席。添加模型后,新行将插入正文并自动渲染。
然后我们有:
var ships = new Backbone.Collection;
ships.on("add", function(ship) {
alert("Ahoy " + ship.get("name") + "!");
});
ships.add([
{name: "Flying Dutchman"},
{name: "Black Pearl"}
]);
希望这对您有帮助;)
关于javascript - 在 Backgrid 列中添加元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35620532/