【问题标题】:concatenate two fields in Extjs store连接 Extjs 存储中的两个字段
【发布时间】:2013-03-23 06:06:45
【问题描述】:

嗨,我正在尝试在网格中插入一个新行,但其中一列实际上是两个值的串联,我想做这样的事情:

    var scopename = newScopeRef.down('textfield[id=scope_name]').getValue();
    var prodname = newScopeRef.down('combobox[id=prd]').getRawValue();
    var relname = newScopeRef.down('combobox[id=p_rls]').getRawValue();


 var editscopegrid = newScopeRef.down('gridpanel[id=editedscope_grid]'); //my grid
    editscopegrid.getView().getStore().removeAll();
    editscopegrid.getView().getStore().add({
                       name_scope : scopename,
                       prodrel : concat(prodrel + ',' prodname + ' ' + relname)});  
    editscopegrid.getView().refresh();

如您所见,我想将网格的prodrel 列的现有值与组合框prodnamerelname 的值连接起来,用空格分隔。

我正在使用带有 MVC 架构的 Extjs 4.x,上面是我面板上“更新”按钮的单击事件的处理程序。

请问我该怎么做?

【问题讨论】:

  • 也许我在问题中遗漏了一些东西,但您不需要函数来连接 Javascript 中的字符串,您使用的是concat。只需使用+ 运算符。除非我错过了这个 Q 的含义,否则这是上面代码的唯一问题。

标签: gridview extjs store


【解决方案1】:

如果您有明确的模型定义,您可以添加带有convert 函数的prodrel 字段并在那里进行连接。

Ext.define('MyModel', {
    extend : 'Ext.data.Model', 
    fields : [
        'name_scope',
        'prodname',
        'relname',
        {
            name    : 'prodrel', 
            convert : function (v, rec) {
               return rec.get('prodname') + ' ' + rec.get('relname');
            }
        }
    ]
}

然后你可以像这样向你的商店添加一个实例......

editscopegrid.getView().getStore().add({
                       name_scope : scopename,
                       prodname   : prodname,
                       relname    : relname});

【讨论】:

    猜你喜欢
    • 2013-02-22
    • 1970-01-01
    • 2013-10-02
    • 2010-12-31
    • 1970-01-01
    • 2021-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多