【问题标题】:Populating form textarea value from array从数组中填充表单文本区域值
【发布时间】:2014-01-11 15:51:53
【问题描述】:

我有一个简单的表格。从服务器返回的 json 值如下:

{
"success":true,
"data":{
    "DNR_ID":"9",
    "DNR_TYPE_ID":"1",
    "DNR_DEF_ID":"1",
    "DNR_DESC":"PROCTOR & GAMBLE HAFTASONU AKSIYONU",
    "STORES": {
        "0" => "ANKARA"
        "1" => "ISTANBUL"
    }
}
}

如您所见,data 中有一个数组,即STORES。所以,我想要做的是,将这些值放入表单中可用的 textarea 中。

ExtJS 的简单表单机制不起作用。

listeners: {
    select: function() {
        if (this.getSelectionModel().hasSelection()) {
            var row = this.getSelectionModel().getSelection()[0];

            Ext.getCmp('dnr-list-info').getForm().load({
                url: '<?php echo base_url() ?>/list/get_dnr_info',
                params: {dnrid: row.get('DNR_ID')},
                method: 'GET',
                success: function(res) {
                    // In fact, this line doesn't necessary because form load function automatically fill the form
                    Ext.getCmp('dnr-list-info').getForm().setValues(res);
                }
            });
        }
    }
}

【问题讨论】:

    标签: forms extjs extjs4.2 populate


    【解决方案1】:

    你需要去down到textarea组件和setValue那里。

    myForm.down('#itemIdForTextArea').setValue('myValue');
    

    或者你也可以直接通过item id查询textarea...

    Ext.ComponentQuery.query('#itemIdForTextArea')[0].setValue('myValue');
    

    或身份证..

    Ext.getCmp('idForTextArea').setValue('myValue');
    

    更多信息请访问sencha docs

    【讨论】:

    • 另外,如果您尝试使用记录中的数据加载表单。您可以使用 loadRecord。只需确保 textarea 上的名称与商店中的名称相对应即可。
    猜你喜欢
    • 2023-03-21
    • 2017-07-04
    • 1970-01-01
    • 2020-11-08
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 2012-02-16
    相关资源
    最近更新 更多