Extjs 几个方法的讨论

  作者:bea

相信大家在做Extjs开发的时候都使用过类似下面的代码:         代码如下: var form_pz = new Ext.form.FormPanel({ id: "form_pz", region: "center", labelAlign: "right", lazyRender: true, frame: true, items: [{ xtype: "combo", fieldLabel: "产品名称", id: "CPMC", al
相信大家在做Extjs开发的时候都使用过类似下面的代码:
      


代码如下:


var form_pz = new Ext.form.FormPanel({
id: "form_pz",
region: "center",
labelAlign: "right",
lazyRender: true,
frame: true,
items: [{
xtype: "combo",
fieldLabel: "产品名称",
id: "CPMC",
allowBlank: false,
store: new Ext.data.SimpleStore({//store的定义}),
displayField: "CPMC_BBH",
valueField: "ID",
anchor: "100%",
mode: "local",
triggerAction: "all",
readOnly: true,
typeAhead: true,

     }]

     });

     var data = [];//里面定义任意数据

     Ext.getCmp("Store_id").load(data);


    此时对这个下拉框以下操作的时候,即让它默认选中Store中第一行数据:


代码如下:



    var record= Ext.getCmp("CPMC").getStore().getAt(0);

    var value = record.get("ID");

    Ext.getCmp("CPMC").setValue(value);


    以上是主要程序,这样运行以后,下拉框是不会自动选中的,
然而把Store单独拿出来定义:


代码如下:



   var Strore_CPMC = new Ext.data.SimpleStore({//定义});

   Strore_CPMC.load(data);

   var record= Ext.getCmp("CPMC").getStore().getAt(0);


  var value = record.get("ID");

   Ext.getCmp("CPMC").setValue(value);


    下拉框就会自动选择store中的第一行数据,其实在其他的方法也存在类似的问题,不知道这是什么原因。望各位朋友指教。


有用  |  无用

猜你喜欢