0

我需要帮助,因为从 xml 创建 TreeStore 时遇到问题(存储用于 NestedList)。查看Javascript代码如下。

{
            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 top-level magazineNumber, 3 - children, 2-nd top-level magazineNumber, 3 childred ),但是如果我点击顶级项目(就 xml 文件数据而言) 它显示了 3 个项目的孩子。如果点击子项 - 嵌套列表将返回“平面”视图。

我应该将自关联模型与其他关联配置或嵌套模型一起使用,我应该将“项目”字段添加到模型还是以某种方式更改存储\代理配置?

一些代码示例将不胜感激。

谢谢 :)

4

1 回答 1

0

你能试试这个

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

并进入store: { ..., autoLoad: true }

我希望这有帮助。:) 再见。

于 2012-06-13T18:13:47.870 回答