首页 > 代码库 > Extjs关于combobox的二三事

Extjs关于combobox的二三事

1.获取combobox 的displayField和valueField分别用:Ext.getCmp(‘id’).getRawValue()和Ext.getCmp(‘id’).getValue()

2.Ext.tab.Panel设置当前活动页:

centerSouthPan.setActiveTab(0);//第一页为活动页,括号内可以填写panel的子项的id或者索引

3.treePanel的初始化默认选中某一项:

var record = treePanel.getStore().getNodeById(categoryid);
        treePanel.getSelectionModel().select(record);

4.grid初始化默认选中一行:

在grid的store加载时用回调函数实现,两种都能实现

s_store.on(‘load‘,{

var item = s_store.getAt(s_store.find("product_id", selectproductid));//行對象獲取
                Ext.getCmp(‘searchGrid‘).getSelectionModel().select(item);//勾选上索引为item的行

});

根据实际使用的情况:

推荐下面的写法:

s_store.load({
            params: {
                category_id: categoryid
            }, callback: function () {
                var item = s_store.getAt(s_store.find("product_id", selectproductid));//行對象獲取
                Ext.getCmp(‘searchGrid‘).getSelectionModel().select(item);//勾选上索引为item的行
            }
        });

最后上传一段实例代码:

  1 Ext.Loader.setConfig({ enabled: true });  2 Ext.Loader.setPath(‘Ext.ux‘, ‘/Scripts/Ext4.0/ux‘);  3 Ext.require([  4     ‘Ext.form.Panel‘,  5     ‘Ext.ux.form.MultiSelect‘,  6     ‘Ext.ux.form.ItemSelector‘  7 ]);  8   9 var titleName = "區域包名稱:"; 10 var leftW = 250; //左側樹狀結構的寬度 11 var conW = 300; //右側的寬度 12 var theight = 320; //窗口的高度 13 var topheight = 100; //窗口的高度 14 var pageSize = 500; 15 var leftW = 250; //左側樹狀結構的寬度 16 var rigW = 560; //右側的寬度 17 var theight = 620; //窗口的高度 18 var topheight = 170; //窗口的高度 19 var pageSize = 500; 20 var s_store; 21 var mainTainProduCateID = "0"; //活動類別ID 22 var siteid = 1; 23 var promationWin; 24 var boolClass = false; 25 var centerNorthPan; 26 var p_store; 27 var isSearchProduct = 0;//是否進行搜尋操作 >0的時候進行搜尋 28 var categoryId = "";    //商品類別編號 29 var categoryName = "";  //商品類別名稱 30 var categoryid = ‘‘; 31 var selectproductid = ‘‘; 32 var packetid = 0; 33 var treePanel; 34 var treeStore; 35 var centerPanel; 36 var searchGrid; 37 var productGrid; 38 Ext.onReady(function () { 39  40  41     var productPro = [ 42      { name: ‘product_id‘, type: ‘int‘ }, 43      { name: ‘brand_id‘, type: ‘string‘ }, 44      { name: ‘category_id‘, type: ‘string‘ }, 45      { name: ‘category_name‘, type: ‘string‘ }, 46      { name: ‘brand_name‘, type: ‘string‘ }, 47      { name: ‘product_name‘, type: ‘string‘ }, 48      { name: ‘product_price_list‘, type: ‘int‘ }, 49      { name: ‘product_status‘, type: ‘string‘ }, 50      { name: ‘product_mode‘, type: ‘string‘ }, 51      { name: ‘combination‘, type: ‘string‘ }, 52      { name: ‘product_freight_set‘, type: ‘string‘ } 53     ]; 54     //所有商品的store 55     Ext.define(‘GIGADE.allPRODUCT‘, { 56         extend: ‘Ext.data.Model‘, 57         fields: productPro 58     }); 59  60  61     Ext.define(‘GIGADE.searchProduct‘, { 62         extend: ‘Ext.data.Model‘, 63         fields: productPro 64     }); 65  66  67  68     //館別Model 69     Ext.define("gigade.shopClass", { 70         extend: ‘Ext.data.Model‘, 71         fields: [ 72             { name: "class_id", type: "string" }, 73             { name: "class_name", type: "string" }] 74     }); 75     //獲取館別 76     var shopClassStore = Ext.create(‘Ext.data.Store‘, { 77         model: ‘gigade.shopClass‘, 78         autoLoad: true, 79         proxy: { 80             type: ‘ajax‘, 81             url: "/PromotionsMaintain/GetShopClass", 82             actionMethods: ‘post‘, 83             reader: { 84                 type: ‘json‘, 85                 root: ‘data‘ 86             } 87         } 88     }); 89     Ext.define("gigade.Brand", { 90         extend: ‘Ext.data.Model‘, 91         fields: [ 92         { name: "brand_id", type: "string" }, 93         { name: "brand_name", type: "string" }] 94     }); 95     //品牌store 96     var classBrandStore = Ext.create(‘Ext.data.Store‘, { 97         model: ‘gigade.Brand‘, 98         autoLoad: false, 99         autoDestroy: true, //自動銷毀100         remoteSort: false,101         proxy: {102             type: ‘ajax‘,103             url: "/PromotionsMaintain/QueryClassBrand",104             actionMethods: ‘post‘,105             reader: {106                 type: ‘json‘,107                 root: ‘item‘108             }109         }110     });111     //獲取左邊的category樹結構(商品分類store)112     treeStore = Ext.create(‘Ext.data.TreeStore‘, {113         autoLoad: true,114         proxy: {115             type: ‘ajax‘,116             url: ‘/Product/GetProductCatagory‘,117             actionMethods: ‘post‘118         },119         rootVisible: false,120         root: {121             text: ‘商品類別‘,122             expanded: true,123             children: []124         }125     });126     treeStore.load();127     treePanel = new Ext.tree.TreePanel({128         id: ‘treePanel‘,129         region: ‘west‘,130         width: leftW,131         border: 0,132         height: theight,133         store: treeStore,134         listeners: {135             ‘itemclick‘: function (view, record, item, index, e) {136                 nodeId = record.raw.id; //获取点击的节点id137                 nodeText = record.raw.text; //获取点击的节点text138                 categoryId = nodeId;139                 categoryName = nodeText;140                 Ext.getCmp(‘categoryId‘).setValue(categoryId);141                 Ext.getCmp(‘categoryName‘).setValue(categoryName);142                 SearchActivy();143             }144 145         }146 147     });148 149     Ext.define("gigade.paraModel", {150         extend: ‘Ext.data.Model‘,151         fields: [152             { name: ‘parameterCode‘, type: ‘string‘ },153             { name: ‘parameterName‘, type: ‘string‘ }154         ]155     });156     var statusStore = Ext.create("Ext.data.Store", {157         model: ‘gigade.paraModel‘,158         autoLoad: true,159         proxy: {160             type: ‘ajax‘,161             url: ‘/Parameter/QueryPara?paraType=product_status‘,162             noCache: false,163             getMethod: function () { return ‘get‘; },164             actionMethods: ‘post‘,165             reader: {166                 type: ‘json‘,167                 root: ‘items‘168             }169         }170     });171     Ext.define("gigade.Brand", {172         extend: ‘Ext.data.Model‘,173         fields: [174         { name: "brand_id", type: "string" },175         { name: "brand_name", type: "string" }]176     });177 178     //品牌store179     var classBrandStore = Ext.create(‘Ext.data.Store‘, {180         model: ‘gigade.Brand‘,181         autoLoad: false,182         autoDestroy: true, //自動銷毀183         remoteSort: false,184         proxy: {185             type: ‘ajax‘,186             url: "/PromotionsMaintain/QueryClassBrand",187             actionMethods: ‘post‘,188             reader: {189                 type: ‘json‘,190                 root: ‘item‘191             }192         }193     });194 195     classBrandStore.on(‘beforeload‘, function () {196         Ext.apply(classBrandStore.proxy.extraParams, {197             topValue: Ext.htmlEncode(Ext.getCmp("shopClass_id").getValue())198         });199     });200 201     centerNorthPan = new Ext.form.FormPanel({202         //title: ‘搜索框‘,203         region: ‘north‘,204         width: rigW,205         height: topheight,206         labelAlign: ‘right‘,207         buttonAlign: ‘right‘,208         padding: 10,209         border: 0,210         items: [211                   {212                       xtype: ‘fieldcontainer‘,213                       defaults: {214                           labelWidth: 40,215                           width: 120216                       },217                       id: ‘ls‘,218                       combineErrors: true,219                       layout: ‘hbox‘,220                       items: [221              {222                  xtype: ‘combobox‘, //class_id223                  allowBlank: true,224                  fieldLabel: ‘館別‘,225                  editable: false,226                  id: ‘shopClass_id‘,227                  width: 200,228                  name: ‘class_name‘,229                  hiddenName: ‘shopClass_id‘,230                  colName: ‘class_name‘,231                  store: shopClassStore,232                  displayField: ‘class_name‘,233                  valueField: ‘class_id‘,234                  typeAhead: true,235                  forceSelection: false,236                  emptyText: SELECT,237                  listeners: {238                      "select": function (combo, record) {239                          var z = Ext.getCmp("clsssBrand_id");240 241                          var c = Ext.getCmp("comboFrontCage");242                          var ch = Ext.getCmp("comboFrontCage_hide");243                          z.clearValue();244                          z.setDisabled(false);245                          c.setValue("");246                          ch.setValue("");247                          classBrandStore.removeAll();248                          boolClass = true;249                          z.setDisabled(false);250 251                      }252                  }253              },254              {255                  xtype: ‘textfield‘,256                  fieldLabel: ‘所有商品查詢‘,257                  labelWidth: 80,258                  id: ‘key‘,259                  name: ‘key‘,260                  width: 180,261              },262              {263                  xtype: ‘button‘,264                  fieldLabel: PRODVISIT,265                  name: ‘visitdate‘,266                  text: SEARCH,267                  handler: Search268              }269                       ]270                   },271                   {272                       xtype: ‘fieldcontainer‘,273                       defaults: {274                           labelWidth: 40275                       },276                       id: ‘2s‘,277                       combineErrors: true,278                       layout: ‘hbox‘,279                       items: [280                        {281                            xtype: ‘combobox‘, //banner_id282                            allowBlank: true,283                            fieldLabel: BLANDNAME,284                            editable: true,285                            forceSelection: true,286                            id: ‘clsssBrand_id‘,287                            Width: 200,288                            name: ‘clsssbrand_name‘,289                            disabled: true,290                            hiddenname: ‘brand_id‘,291                            store: classBrandStore,292                            displayField: ‘brand_name‘,293                            valueField: ‘brand_id‘,294                            typeAhead: true,295                            forceSelection: false,296                            emptyText: SELECT,297                            listeners: {298                                beforequery: function (qe) {299                                    if (boolClass) {300                                        delete qe.combo.lastQuery;301                                        classBrandStore.load({302                                            params: {303                                                topValue: Ext.getCmp("shopClass_id").getValue()304                                            }305                                        });306                                        boolClass = false;307                                    }308                                },309                                ‘blur‘: function () {310                                    var o = classBrandStore.data.items;311                                    if (document.getElementsByName(‘clsssbrand_name‘)[0].value != Ext.getCmp(‘clsssBrand_id‘).getValue()) {312                                        document.getElementsByName(‘clsssbrand_name‘)[0].value = http://www.mamicode.com/classBrandStore.getAt(0).get(‘brand_id‘);313                                    }314                                }315                            }316                        },317                        {318                            xtype: ‘displayfield‘,319                            fieldLabel: ‘類別編號‘,320                            id: ‘categoryId‘,321                            name: ‘categoryId‘,322                            width: 100,323                            labelWidth: 60324                        },325                        {326                            xtype: ‘displayfield‘,327                            fieldLabel: ‘類別名稱‘,328                            id: ‘categoryName‘,329                            name: ‘categoryName‘,330                            labelWidth: 60,331                            width: 200332                        }333                       ]334                   },335                   {336                       xtype: ‘fieldcontainer‘,337                       defaults: {338                           labelWidth: 60,339                           width: 120340                       },341                       id: ‘3s‘,342                       combineErrors: true,343                       layout: ‘hbox‘,344                       items: [345                        {346                            xtype: ‘combobox‘, //status347                            allowBlank: true,348                            fieldLabel: ‘商品狀態‘,349                            editable: true,350                            forceSelection: true,351                            id: ‘s_status‘,352                            width: 200,353                            name: ‘s_status‘,354                            hiddenname: ‘s_status‘,355                            store: statusStore,356                            displayField: ‘parameterName‘,357                            valueField: ‘parameterCode‘,358                            typeAhead: true,359                            forceSelection: false,360                            emptyText: SELECT,361                            listeners: {362                                "select": function (combo, record) {363                                    var z = Ext.getCmp("s_status");364                                    if (z.getValue() == "0" || z.getValue() == "20") {365                                        Ext.Msg.alert(INFORMATION, "不存在該狀態的商品");366                                        z.setValue("");367                                    }368                                }369                            }370                        }, {371                            xtype: ‘textfield‘,372                            fieldLabel: ‘類別商品查詢‘,373                            id: ‘keyactivy‘,374                            name: ‘keyactivy‘,375                            labelWidth: 80,376                            width: 200,377                        },378                        {379                            xtype: ‘button‘,380                            fieldLabel: PRODVISIT,381                            name: ‘visitdate‘,382                            text: SEARCH,383                            handler: SearchActivy384                        }385                       ]386                   },387                   {388                       xtype: ‘combotree‘,389                       id: ‘comboFrontCage‘,390                       name: ‘classname‘,391                       hiddenname: ‘classname‘,392                       hidden: true,393                       editable: false,394                       submitValue: false,395                       colName: ‘category_id‘,396                       store: frontCateStore,397                       fieldLabel: CLASSNAME,398                       height: 200,399                       labelWidth: 60400 401                   },402                  {403                      hidden: true,404                      xtype: ‘textfield‘,405                      id: ‘comboFrontCage_hide‘,406                      name: ‘comboFrontCage_hide‘,407                      width: 10,408                      listeners: {409                          change: function (txt, newValue, oldValue) {410                              if (newValue) {411                                  var z = Ext.getCmp("clsssBrand_id");412                                  var sc = Ext.getCmp("shopClass_id");413                                  z.clearValue();414                                  sc.clearValue();415                                  z.setDisabled(true);416                              }417                          }418                      }419                  }420         ]421     });422 423     s_store = Ext.create(‘Ext.data.Store‘, {424         pageSize: pageSize,425         model: ‘GIGADE.searchProduct‘,426         proxy: {427             type: ‘ajax‘,428             url: ‘/Element/GetProductByCategorySet‘,429             actionMethods: ‘post‘,430             reader: {431                 type: ‘json‘,432                 root: ‘item‘,433                 totalProperty: ‘totalCount‘434             }435         }436     });437     p_store = Ext.create(‘Ext.data.Store‘, {438         pageSize: pageSize,439         model: ‘GIGADE.allPRODUCT‘,440         proxy: {441             type: ‘ajax‘,442             url: ‘/Product/GetAllProList‘,443             actionMethods: ‘post‘,444             reader: {445                 type: ‘json‘,446                 root: ‘item‘,447                 totalProperty: ‘totalCount‘448             }449         }450     });451 452 453     s_store.on("beforeload", function () {454         Ext.apply(s_store.proxy.extraParams, {455             category_id: categoryId,456             status: Ext.getCmp(‘s_status‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘s_status‘).getValue()),457             keyCode: Ext.getCmp(‘keyactivy‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘keyactivy‘).getValue()),458             brand_id: Ext.getCmp(‘clsssBrand_id‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘clsssBrand_id‘).getValue()),459             class_id: Ext.getCmp(‘shopClass_id‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘shopClass_id‘).getValue()),460             comboFrontCage_hide: Ext.getCmp(‘comboFrontCage_hide‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘comboFrontCage_hide‘).getValue())461 462         });463     });464     p_store.on("beforeload", function () {465         Ext.apply(p_store.proxy.extraParams, {466             status: Ext.getCmp(‘s_status‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘s_status‘).getValue()),467             keyCode: Ext.getCmp(‘key‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘key‘).getValue()),468             brand_id: Ext.getCmp(‘clsssBrand_id‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘clsssBrand_id‘).getValue()),469             class_id: Ext.getCmp(‘shopClass_id‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘shopClass_id‘).getValue()),470             comboFrontCage_hide: Ext.getCmp(‘comboFrontCage_hide‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘comboFrontCage_hide‘).getValue())471 472         });473     });474 475     function Search() {476         p_store.removeAll();477         p_store.load();478     }479     function SearchActivy() {480         s_store.removeAll();481         s_store.load({482             params: {483                 category_id: categoryId,484                 status: Ext.getCmp(‘s_status‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘s_status‘).getValue()),485                 keyCode: Ext.getCmp(‘keyactivy‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘keyactivy‘).getValue()),486                 brand_id: Ext.getCmp(‘clsssBrand_id‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘clsssBrand_id‘).getValue()),487                 class_id: Ext.getCmp(‘shopClass_id‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘shopClass_id‘).getValue()),488                 comboFrontCage_hide: Ext.getCmp(‘comboFrontCage_hide‘).getValue() == ‘‘ ? ‘‘ : Ext.htmlEncode(Ext.getCmp(‘comboFrontCage_hide‘).getValue())489 490             }491         });492     }493 494     //控制productGrid中的按鈕495     var t_product_cm = Ext.create(‘Ext.selection.CheckboxModel‘, {496         listeners: {497             selectionchange: function (sm, selections) {498                 Ext.getCmp("productGrid").down(‘#t_save‘).setDisabled(selections.length == 0);499             }500         }501     });502     //控制類別中商品的控件  503     var t_search_cm = Ext.create(‘Ext.selection.CheckboxModel‘, {504         listeners: {505             selectionchange: function (sm, selections) {506                 Ext.getCmp("searchGrid").down(‘#t_all_save‘).setDisabled(selections.length == 0);507             }508         }509     });510 511     //顯示所有商品512     productGrid = new Ext.grid.Panel({513         id: ‘productGrid‘,514         store: p_store,515         region: ‘center‘,516         selModel: t_product_cm,517         autoScroll: true,518         border: 0,519         height: 390,520         viewConfig: {521             enableTextSelection: true,522             stripeRows: false,523             getRowClass: function (record, rowIndex, rowParams, store) {524                 return "x-selectable";525             }526         },527         columns: [528                   { header: ‘商品編號‘, dataIndex: ‘product_id‘, width: 60, align: ‘center‘ },529                   { header: ‘商品名稱‘, dataIndex: ‘product_name‘, width: 180, align: ‘center‘ },530                   { header: ‘品牌‘, dataIndex: ‘brand_name‘, width: 120, align: ‘center‘ },531                   { header: ‘組合類型‘, dataIndex: ‘combination‘, width: 120, align: ‘center‘, hidden: true },532                   { header: ‘商品狀態‘, dataIndex: ‘product_status‘, width: 80, align: ‘center‘ },533                   { header: ‘運送方式‘, dataIndex: ‘product_freight_set‘, width: 60, align: ‘center‘, hidden: true },534                   { header: ‘出貨方式‘, dataIndex: ‘product_mode‘, width: 60, align: ‘center‘, hidden: true }535         ],536         tbar: [537               { xtype: ‘button‘, id: ‘t_save‘, text: ‘確定‘, iconCls: ‘icon-add‘, disabled: true, handler: function () { onAddEleClick(); } }538         ],539         bbar: Ext.create(‘Ext.PagingToolbar‘, {540             store: p_store,541             pageSize: pageSize,542             displayInfo: true,543             displayMsg: NOW_DISPLAY_RECORD + ‘: {0} - {1}‘ + TOTAL + ‘: {2}‘,544             emptyMsg: NOTHING_DISPLAY545         }),546         listeners: {547             scrollershow: function (scroller) {548                 if (scroller && scroller.scrollEl) {549                     scroller.clearManagedListeners();550                     scroller.mon(scroller.scrollEl, ‘scroll‘, scroller.onElScroll, scroller);551                 }552             }553         }554     });555     //顯示類別中商品的grid556     searchGrid = new Ext.grid.Panel({557         id: ‘searchGrid‘,558         store: s_store,559         region: ‘center‘,560         autoScroll: true,561         selModel: t_search_cm,562         autoScroll: true,563         border: 0,564         height: 390,565         viewConfig: {566             enableTextSelection: true,567             stripeRows: false,568             getRowClass: function (record, rowIndex, rowParams, store) {569                 return "x-selectable";570             }571         },572         columns: [573                  { header: ‘類別‘, dataIndex: ‘category_name‘, width: 120, align: ‘center‘ },574                  { header: ‘商品編號‘, dataIndex: ‘product_id‘, width: 60, align: ‘center‘ },575                  { header: ‘商品名稱‘, dataIndex: ‘product_name‘, width: 180, align: ‘center‘ },576 577                  { header: ‘品牌‘, dataIndex: ‘brand_name‘, width: 120, align: ‘center‘ },578                  { header: ‘組合類型‘, dataIndex: ‘combination‘, width: 120, align: ‘center‘, hidden: true },579                  { header: ‘商品狀態‘, dataIndex: ‘product_status‘, width: 80, align: ‘center‘, hidden: true },580                  { header: ‘運送方式‘, dataIndex: ‘product_freight_set‘, width: 60, align: ‘center‘, hidden: true },581                  { header: ‘出貨方式‘, dataIndex: ‘product_mode‘, width: 60, align: ‘center‘, hidden: true }582         ],583         tbar: [584             { xtype: ‘button‘, id: ‘t_all_save‘, text: ‘確定‘, iconCls: ‘icon-add‘, disabled: true, handler: function () { onAddEleCaClick(); } }585         ],586         bbar: Ext.create(‘Ext.PagingToolbar‘, {587             store: s_store,588             pageSize: pageSize,589             displayInfo: true,590             displayMsg: NOW_DISPLAY_RECORD + ‘: {0} - {1}‘ + TOTAL + ‘: {2}‘,591             emptyMsg: NOTHING_DISPLAY592         }),593         listeners: {594             scrollershow: function (scroller) {595                 if (scroller && scroller.scrollEl) {596                     scroller.clearManagedListeners();597                     scroller.mon(scroller.scrollEl, ‘scroll‘, scroller.onElScroll, scroller);598                 }599             }600         }601     });602 603 604     centerSouthPan = new Ext.tab.Panel({605         region: ‘center‘,606         autoScroll: true,607         items: [608             {609                 title: ‘類別商品‘,610                 items: [searchGrid]611             }, {612                 title: ‘所有商品‘,613                 items: [productGrid]614             }615         ]616     });617 618     var centerPanel = new Ext.Panel({619         region: ‘center‘,620         items: [centerNorthPan, centerSouthPan]621     });622 623     //頁面佈局624     promationWin = new Ext.Window({625         //title: titleName,626         height: theight,627         width: leftW + rigW,628         layout: ‘border‘,629         modal: true,630         constrain: true,631         closeAction: ‘hide‘, //hide632         items: [633             //topPanel,634             treePanel,635             centerPanel636         ]637     });638 639 640 641 });642 643 function ElementProductShow(packetid, packetname, categoryid, selectproductid) {644     titleName += packetname;645     promationWin.title = titleName;646     packetid = packetid;647     promationWin.show();648     centerNorthPan.form.reset();649     s_store.removeAll();650     p_store.removeAll();651     p_store.load();652     if (categoryid != ‘0‘ && categoryid != ‘‘) {653 654 655         var record = treePanel.getStore().getNodeById(categoryid);656         treePanel.getSelectionModel().select(record);657 658         Ext.getCmp(‘categoryId‘).setValue(record.raw.id);659         Ext.getCmp(‘categoryName‘).setValue(record.raw.text);660         s_store.load({661             params: {662                 category_id: categoryid663             }, callback: function () {664                 var item = s_store.getAt(s_store.find("product_id", selectproductid));//行對象獲取665                 Ext.getCmp(‘searchGrid‘).getSelectionModel().select(item);666             }667         });668         centerSouthPan.setActiveTab(0);669 670     } else {671         centerSouthPan.setActiveTab(1);672         p_store.load({673             callback: function () {674             var itemP = p_store.getAt(p_store.find("product_id", selectproductid));//行對象獲取675             Ext.getCmp(‘productGrid‘).getSelectionModel().select(itemP);676         }677         });678     }679 680 }681 682 function onAddEleCaClick() {683     if (Ext.getCmp(‘productGrid‘).getSelectionModel().getSelection().length != 0) {684         Ext.Msg.alert(INFORMATION, SELECPROTTIP);685         return;686     }687     var row = Ext.getCmp(‘searchGrid‘).getSelectionModel().getSelection();688 689     if (row.length == 0) {690         Ext.Msg.alert(INFORMATION, NO_SELECTION);691     } else if (row.length > 1) {692         Ext.Msg.alert(INFORMATION, ONE_SELECTION);693     } else if (row.length == 1) {694         promationWin.close();695         Ext.getCmp(‘product_id‘).setValue(row[0].data.product_id);696         Ext.getCmp(‘category_id‘).setValue(row[0].data.category_id);697         Ext.getCmp(‘category_name‘).show();698         Ext.getCmp(‘category_name‘).setValue(row[0].data.category_name);699     }700 }701 702 function onAddEleClick() {703     if (Ext.getCmp(‘searchGrid‘).getSelectionModel().getSelection().length != 0) {704         Ext.Msg.alert(INFORMATION, SELECPROTTIP);705         return;706     }707 708     var row = Ext.getCmp(‘productGrid‘).getSelectionModel().getSelection();709 710     if (row.length == 0) {711         Ext.Msg.alert(INFORMATION, NO_SELECTION);712     } else if (row.length > 1) {713         Ext.Msg.alert(INFORMATION, ONE_SELECTION);714     } else if (row.length == 1) {715         Ext.getCmp(‘category_name‘).setValue("");716         Ext.getCmp(‘category_id‘).setValue(0);717         Ext.getCmp(‘product_id‘).setValue(row[0].data.product_id);718         Ext.getCmp(‘category_name‘).hide();719         promationWin.close();720     }721 }
这是一段常用布局的代码:上面卤煮菜鸟遇到的问题解决办发效果如下图

Extjs关于combobox的二三事