我正在创建一个基于数据源的dgrid,该数据源具有一个地址和两列布尔值,用于标识记录中的地址类型,邮政地址或公司地址。
我想基于两个布尔列在另一列(地址类型)中显示布尔值的描述性名称。我试图使用dgrid格式化程序功能,但我无法得到所需的结果。以下是我的代码:
的Javascript
function getAddressType(){
$.each(employeeAddressData, function(key, value){
if(key == "postalAddress"){
if(value == true || value == 'true'){
console.log('returning postal');
return 'Postal';
}
}else{
console.log('returning business');
return 'Business';
}
});
}
var Employer = [{id: 1, businessName:'John Doe and Sons Limited',phone:'123456',address:'123 Long Street', postalAddress:true, businessAddress:false},
{id: 1, businessName:'Alice and Bob Limited',phone:'78956', address:'56 Short Street', postalAddress:false, businessAddress:true}];
var employerGrid = new CustomGrid({
store: employerStore,
columns:{
id:{
label:"Id",
field:"id",
hidden:true
},
businessName:{
label:"Business",
field:"businessName",
},
phone:{
label:"Contact No.",
field:"phone",
},
address:{
label:"Address",
field:"address",
},
addressType:{
label:"Address Type",
formatter:getAddressType();
}
},
selectionMode:"none",
loadingMessage: "Loading data...",
noDataMessage: "No results found....",
allowSelectAll: true
}, "employerGrid");
答案 0 :(得分:4)
我意识到dgrid有一个get函数,我可以使用它来访问数据源属性。因此不需要格式化,而是使用了get。 Under是我的解决方案:
<强>的Javascript 强>
},
addressType:{
label:"Address Type",
get: function(object){
if(object.postalAddress == true){
return 'Postal';
}else{
return 'Business';
}
}
}