首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何使用Extjs Form loadRecord设置checkbox和combobox的值?

如何使用Extjs Form loadRecord设置checkbox和combobox的值?
EN

Stack Overflow用户
提问于 2013-05-20 13:06:59
回答 1查看 14.5K关注 0票数 3

当我运行form.loadRecord(record);时,数据会出现在四字段中,但复选框和使用id值的组合框对于所有...我尝试过很多解决这个问题的方法,但对我来说都不起作用。

代码语言:javascript
运行
AI代码解释
复制
    Ext.define('Ext.migration.ProductEditPanel', { 
        extend:  'Ext.panel.Panel',
        alias: 'widget.producteditpanel',
        title: 'Genel Bilgiler',
        layout: 'column',
        bodyPadding: 5,
        ds_activeProductTypes: this.ds_activeProductTypes,
        initComponent: function() {
            this.items = [{
                columnWidth: 0.5,
                xtype: 'form',
                id: 'productcrudform',
                margin: '0 5 0 0',
                bodyPadding: 5,
                name: 'productcrudform',
                url: baseUrl + "productcrud",
                defaultType: 'textfield',
                items: [{
                        scale: this,
                        inputType: 'hidden',
                        id: 'actionType',
                        name: 'actionType',
                        value: this.actionType
                    },{
                        fieldLabel: 'ID',labelWidth: 140,
                        id: 'id',
                        name: 'id',
                        disabled: true,
                        anchor : '100%'
                    },{
                        fieldLabel: 'Ürün Adı',labelWidth: 140, anchor : '100%',
                        id: 'name',
                        name: 'name'                            
                    },{
                        fieldLabel: 'Kod', labelWidth: 140, anchor : '100%',
                        name: 'code',
                    },
                    {
                        xtype : 'combo', labelWidth: 140, anchor : '100%',
                        fieldLabel : 'Ürün Tipi',
                        name : 'productType.name',
                        hiddenName : 'productType.id',
                        store : new Ext.data.ArrayStore({
                            fields : [ 'productType.id', 'productType.name'],
                            data : [
                                [ 1, 'TISORT'],
                                [ 2, 'POSTER'],
                                [ 3, 'KAPSONLU'],
                                [ 4, 'TELEFON_KAPAK']]
                        }),
                        mode : 'local', 
                        valueField : 'productType.id',
                        displayField : 'productType.name'
                    },{
                        fieldLabel: 'Aktif', labelWidth: 140, width: 180,
                        inputType: 'checkbox',
                        name: 'activeFlag'
                    },{
                        name: 'newFlag',
                        fieldLabel: 'Yeni Ürün', labelWidth: 140, width: 180,
                        inputType: 'checkbox'
                    },{
                        name: 'clearanceFlag',
                        fieldLabel: 'Tasfiye Ürün', labelWidth: 140, width: 180, anchor : '0%',
                        inputType: 'checkbox'
                    }
                ]
            },
            {   // PRICE GRID INIT
                columnWidth: 0.5,
                title: 'Prices',
                requires: 'Ext.migration.PriceGrid',
                xtype: 'productpricegrid',
                id: 'prices-grid',
                region: 'center',
                border: true,
                store: pricesStore
            }];

            this.callParent(arguments);
        },            
        onSubmit: function() {}
    });

解决方案1:

代码语言:javascript
运行
AI代码解释
复制
field: {
    xtype: 'checkboxfield',
    name: 'active_state',
    value: 1,
    inputValue: 1,
    uncheckedValue: 0
}

或者:

代码语言:javascript
运行
AI代码解释
复制
field: {
    xtype: 'checkboxfield',
    name: 'active_state',
    value: 1,
    inputValue: true,
    uncheckedValue: false
}

或者:

代码语言:javascript
运行
AI代码解释
复制
field: {
    xtype: 'checkboxfield',
    name: 'active_state',
    value: 1,
    inputValue: 'true',
    uncheckedValue: 'false'
}
EN

回答 1

Stack Overflow用户

发布于 2013-09-10 10:15:27

当您调用loadRecord时,对于记录的每个字段,都会搜索一个同名的表单域,如果找到,则会调用该记录的"setValue“,因此您必须查看该方法中的复选框和组合框。对于复选框,这是相当简单的:默认情况下,只有这些值会选中您的复选框:

代码语言:javascript
运行
AI代码解释
复制
true
'true'
'1'
'on'

而任何其他值都会将其检查为false。因此,如果模型中的字段被定义为boolean类型,则一切正常(因此,您可能应该检查模型字段和表单项名称是否匹配)。如果需要一个自定义的"true“值,只需指定inputValue属性即可。

对于组合框,如果它们的存储被设置为remote,并且被设置为forceSelection true,并且值字段与显示字段不同,则会有点复杂,但在您的示例中应该没有任何问题。我认为你的问题是你使用的是ArrayStore,直接切换到数据存储。

jsfiddle example

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16650244

复制
相关文章

相似问题

领券
社区富文本编辑器全新改版!诚邀体验~
全新交互,全新视觉,新增快捷键、悬浮工具栏、高亮块等功能并同时优化现有功能,全面提升创作效率和体验
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
查看详情【社区公告】 技术创作特训营有奖征文