javascript - 道场数据网格 : Multiple values in a single field

标签 javascript arrays dojo dojox.grid.datagrid

我正在使用 Dojo 1.7,我在数据网格中有一个字段可以没有值、一个值或多个值。我正在尝试使用这种格式的数据:

//data
var store2 = new dojo.data.ItemFileReadStore({
    data: {
        identifier: "id",
        items: [
            {id: 1, 'personNames': ['Steve', 'Roy', 'Gary']},
            {id: 2, 'personNames': ''} //blank, no person names

        ]
    }
});

//formater
function formatPersonNames(value){
 if (value == '') {
   return '<p>Nobody here</p>';
 } else {
   return value + '<p style="margin-top:10px;">Check out the names above!</p>';
 };
};

这是布局:

// layout
var layout2 = [
    {name: 'Display Order', field: 'id', noresize:true, 'width': '50px'},
    {name: 'Person Names', field: 'personNames', formatter: formatPersonNames, noresize:true}
];

问题是只显示名字“Steve”。我尝试使用 value[0] 作为测试,但只显示了第一个字母。我是这类东西的新手,所以任何建议将不胜感激。

最佳答案

问题是,您的格式化函数仅接收数组项的第一个。 Dojo 不会像您希望的那样处理数组。在传递给 dojo 之前,您需要格式化数据:

for (var i=0;i<items.length;i++) {
  if (items[i].personNames instanceof Array)
    items[i].personNames = items[i].personNames.join(', ')
}

关于javascript - 道场数据网格 : Multiple values in a single field,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17887003/

相关文章:

javascript - onclick 定位特定类

java - 粒子系统中的 Array NullPointerException

arrays - 在 Swift 中对字符串字典数组进行排序

css - 道场图标元素 : class name of a DOM button as icon

javascript - Google Script 等于日期?

javascript - 在 JSApi 中获取连接电子邮件和名称时出现 Linkedin 403 禁止错误

ruby - 从对象数组中获取包含特定值的数组的最 Rubyish 方式?

javascript - 如何将 JsonRestStore 与我的 RESTful 服务结合使用

javascript - Dojo/Dijit - DateTextBox 隐藏了我的初始值

javascript - 示例在 js-fiddle 中有效,但在自制页面中无效