2013-11-24 106 views
0

我使用的是ext-4.2.1,下面是代碼。它有兩個問題,(1)buildCategoryStore(),組合無法找到商店。 (2)下面是xml數據,看起來像商店xml讀取器不工作,如何設置xml根目錄?Extjs 4組合xml存儲加載?

感謝

Ext.define('App.view.QuestionForm',{ 
    extend  : 'Ext.form.Panel', 
    alias  : 'widget.QuestionForm', 
    requires : [], 

    initComponent : function(){ 
     var me = this; 

     me.items = me.buildItems();  
     me.callParent(); 
    }, 

    buildCategoryStore: function(){ 
     var CategoryStore = Ext.create('Ext.data.Store', { 
      autoLoad: true, 
      fields: ['id','name'], 
      proxy: { 
       type: 'ajax', 
       url: 'rs/question/getAllCategories', 
       reader: { 
        type:'xml', 
        root: 'CategoryList' 
       } 
      }, 
      storeId: 'CategoryStore', 
      root: 'CategoryList' 
     }); 
     return CategoryStore; 
    }, 
    buildItems : function(){ 
     return [ 
     { 
      xtype: 'combo', 
      anchor: '100%', 
      fieldLabel : 'Category', 
      store: buildCategoryStore(), 
      name: 'category',   
      mode: 'local', 
      multiSelect: false 
     }, 

     ]; 
    }, 

    } 

}); 

XML數據:

<CategoryList> 

<Category> 
<active>Y</active> 
<id>1000</id> 
<name>Life</name> 
<versionNum>0</versionNum> 
</Category> 

<Category> 
<active>Y</active> 
<id>1001</id> 
<name>Career</name> 
<versionNum>0</versionNum> 
</Category> 
</CategoryList> 

回答

0

我搞掂你的代碼。重要的部分是你需要撥打this.foo(),你需要指定讀者的記錄參數。

Ext.define('App.view.QuestionForm', { 
    extend: 'Ext.form.Panel', 
    alias: 'widget.QuestionForm', 

    requires: [ 
     'Ext.data.Store' 
    ], 

    initComponent: function() { 
     this.items = this.buildItems(); 
     this.callParent(); 
    }, 

    buildCategoryStore: function() { 
     return new Ext.data.Store({ 
      autoLoad: true, 
      fields: ['id', 'name'], 
      proxy: { 
       type: 'ajax', 
       url: 'rs/question/getAllCategories', 
       reader: { 
        type: 'xml', 
        record: 'Category' 
       } 
      } 
     }); 
    }, 

    buildItems: function() { 
     return [{ 
      xtype: 'combo', 
      anchor: '100%', 
      fieldLabel: 'Category', 
      store: this.buildCategoryStore(), 
      name: 'category', 
      mode: 'local', 
      multiSelect: false, 
      valueField: 'id', 
      displayField: 'name' 
     }]; 
    } 
}); 
+0

謝謝。第一部分是固定的。但是對於第二個,它仍然沒有在下拉菜單中顯示選項值。 – user595234

+0

您還缺少displayField/valueField。 –

+0

是的,它現在有效。你是一個超級男人。 Extjs對我來說很難調試。你是如何發現這個錯誤的? – user595234