2012-06-13 32 views
0

我需要幫助,因爲從xml創建TreeStore時存在問題(存儲區是針對NestedList的)。 查看Javascript代碼如下。來自XML的Sencha Touch 2 TreeStore

{ 
      xtype: 'nestedlist', 
      title: 'Журнал', 
      iconCls: 'bookmarks', 
      displayField: 'title', 
      store: { 
       type: 'tree', 
       model: 'App.model.magazineNumber', 
       root: { 
        leaf: false 
       }, 
       proxy: { 
        type: 'ajax', 
        url: 'http://localhost:57648/repo/dataMocks/contentListItems.xml', 
        reader: { 
         type: 'xml', 
         rootProperty: 'items', 
         record: 'magazineNumber' 
        } 
       } 
      } 
} 

模型定義

Ext.define('App.model.magazineNumber', { 
extend: 'Ext.data.Model', 
config: { 
    fields: 
     [ 
      'title', 
      'description', 
      { 
       name: 'leaf', 
       defaultValue: false 
      }] 
//this doesn't help 
//  , hasMany: [{ 
//   model: 'App.model.magazineNumber', 
//   name: 'items' 
//  }] 
//  , belongsTo: 'App.model.magazineNumber' 
    } 
}); 

和XML文件

<?xml version="1.0" encoding="utf-8" ?> 
<items> 
    <magazineNumber> 
    <title>Первый номер</title> 
    <description>Описание первого номера</description> 
    <items> 
     <magazineNumber> 
     <title>Статья один</title> 
     <description>Описание cтатьи один</description> 
     <contentItemId>1</contentItemId> 
     </magazineNumber> 
     <magazineNumber> 
     <title>Статья два</title> 
     <description>Описание cтатьи два</description> 
     <contentItemId>2</contentItemId> 
     </magazineNumber> 
     <magazineNumber> 
     <title>Статья три</title> 
     <description>Описание cтатьи три</description> 
     <contentItemId>3</contentItemId> 
     </magazineNumber> 
    </items> 
    </magazineNumber> 
    <magazineNumber> 
    <id>5</id> 
    <title>Второй номер</title> 
    <description>Описание второго номера</description> 
    <items> 
     <magazineNumber> 
     <title>Статья один</title> 
     <description>Описание cтатьи один</description> 
     <contentItemId>4</contentItemId> 
     </magazineNumber> 
     <magazineNumber> 
     <title>Статья два</title> 
     <description>Описание cтатьи два</description> 
     <contentItemId>5</contentItemId> 
     </magazineNumber> 
    </items> 
    </magazineNumber> 
</items> 

而且Nestedlist示出了平面結構(所有項目一次 - 1-ST頂層magazineNumber,3 - 兒童,2 - 頂級magazineNumber,3個孩子),但是如果我點擊頂級項目(根據xml文件數據),它會顯示3個項目的孩子。如果點按兒童 - 嵌套列表會回到「平面」視圖。

我應該使用與其他關聯配置或嵌套模型自我關聯的模型,我應該添加'項目'字段以某種方式建模或更改商店\代理配置?

一些代碼示例將不勝感激。

謝謝:)

回答

0

你可以試試這個

proxy: { 
    type: 'ajax', 
    url: 'http://localhost:57648/repo/dataMocks/contentListItems.xml', 
    reader: { 
     type: 'xml', 
     record: 'magazineNumber' 
    } 
} 

進入store: { ..., autoLoad: true }

我希望這有助於。 :) 再見。