extjs中加载下拉菜单 并设置默认值

下拉菜单组件

     this.form = Ext.widget('form', {
            border: true,
            bodyPadding: 10,
            autoScroll: true,
            layout: 'column',
            defaults: {
                anchor: '100%'
            },
            defaultType: 'textfield',
            items: [
                {
                    xtype: 'fieldcontainer',
                    layout: 'hbox',
                    combineErrors: true,
                    defaultType: 'textfield',
                    defaults: {
                        labelWidth: 100,
                        labelAlign: 'right',
                        anchor: '100%',
                        margin: '0 10 10 0',
                        width: 200
                    },
                    items: [
                    {
	                    fieldLabel:'品牌商',
	                    name:'company_code',
	                    labelWidth: 50,
				        xtype: 'combo',
				        store: this.AllSaleCompanyStore,
				        queryMode: 'local',
				        displayField: 'name',
				        valueField: 'code',
				        editable: true,
				        width: 200
                     }
                        ]
                },
                
            ],
            buttonAlign: 'left',
            buttons: [
                {
                    text: '重置',
                    scope: this,
                    handler: this.onBtnClick
                },
                {
                    text: '检索',
                    scope: this,
                    handler: this.onBtnClick
                },
            ]
        });
      

请求数据方法:

  getSaleCompany: function () {
        this.setLoading("加载中...");
        var url = 'index.php/supplier_manage/supplier_search?type=2&del_flag=1';
        Ext.Ajax.request({
            url: url,
            method: 'get',
            async: false,//重点 异步加载 一般出现 “全部” 不能默认自动加载 问题一般就是出现在这
            scope: this,
            success: function (response, options) {
                try {
                    var returnobj = Ext.JSON.decode(response.responseText);
                    if (returnobj) {
                        var Allreturnobj = Ext.JSON.decode(response.responseText);
                        for (var i = 0; i < returnobj.records.length; i++) {
                            returnobj.records[i].code = returnobj.records[i].company_code;
                            returnobj.records[i].name = (returnobj.records[i].company_name;
                        }
                        Allreturnobj.records.unshift({id: "", name: "全部", code: ''});
                        this.AllSaleCompanyStore.loadData(Allreturnobj.records);
                    }
                } catch (e) {
                    Ext.Msg.alert("错误", response.responseText);
                }
            },
            failure: function (response, options) {
                Ext.Msg.alert("错误", response.responseText);
            },
            callback: function () {
                this.setLoading(false);
            }
        });
    },

加载数据

 afterRenderHandler: function () {
        this.getSaleCompany();
         var field = this.form.getForm().findField("company_code");
        field.select(field.getStore().getAt(0));
        this.loadData();
    },
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值