Backbone.js Backgrid格式化程序从其他列添加值
是否可以使用BackGrid构建自定义单元格vía格式化程序,从隐藏列组成值Backbone.js Backgrid格式化程序从其他列添加值,backbone.js,backgrid,Backbone.js,Backgrid,是否可以使用BackGrid构建自定义单元格vía格式化程序,从隐藏列组成值 var grid = new Backgrid.Grid({ columns: [ { name:"half_value_1", cell:"string", rendered: false }, { name:"half_value_2", cell:"string", rendered: false }, { name: "compos
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
函数中获得半值\u 1
和半值\u 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;
}
})
}
这对你来说应该是完美的——我在我的项目中的一些网格中使用它。但是我没有测试这段代码,所以我可能有拼写错误:)
钥匙谢谢,钥匙。我不知道我在render上有完整的行模型,而在formatter方法上没有。这是有道理的,因为我正在修改数据结构,而不是演示文稿。没问题,很高兴我能帮上忙!:)