gpt4 book ai didi

backbone.js - Backgrid 格式化程序从其他列添加值

转载 作者:行者123 更新时间:2023-12-04 02:29:08 24 4
gpt4 key购买 nike

是否可以使用 BackGrid 通过格式化程序构建自定义 Cell,从隐藏列中组合值?

var grid = new Backgrid.Grid({
columns: [
{
name:"half_value_1",
cell:"string",
rendered: false
},
{
name:"half_value_2",
cell:"string",
rendered: false
},
{
name: "composite",
cell: "string",
formatter: _.extend({}, Backgrid.CellFormatter.prototype, {
fromRaw: function (half_value_1, half_value_2) {
return half_value_1 + '/' + half_value_2;
}
})
}],
collection: col
});

我可以在 fromRaw 函数中获取 half_value_1half_value_2 吗?

最佳答案

我认为获得所需结果的最佳方法是使用自定义单元格而不是自定义格式化程序。您可以为那个特定的列做这样的事情:

{
name: "composite",
cell: Backgrid.Cell.extend({

render: function(){

// You have access to the whole model - get values like normal in Backbone
var half_value_1 = this.model.get("half_value_1");
var half_value_2 = this.model.get("half_value_2");

// Put what you want inside the cell (Can use .html if HTML formatting is needed)
this.$el.text( half_value_1 + '/' + half_value_2 );

// MUST do this for the grid to not error out
return this;

}

})
}

这应该非常适合您 - 我将它用于我项目中的一些网格。不过我没有测试这段代码,所以我可能有拼写错误:)

key

关于backbone.js - Backgrid 格式化程序从其他列添加值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20093844/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com