Sencha Touch 2 TreeStore from XML

I need help 'cause having problems creating TreeStore from xml (store is for NestedList). View Javascript code is the following.

{
            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'
                    }
                }
            }
}

Model definition

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'
    }
});

and xml file

<?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>

And Nestedlist shows flat structure (all items at once - 1-st top-level magazineNumber, 3 - children, 2-nd top-level magazineNumber, 3 childred ), however if I tap top-level item (in terms of xml file data) it shows 3 item's children. If tap children - nested list goes back to "flat" view.

Should i use self associated model with other associations config or nested models, should i Add 'items' field to model or change store\proxy config in some way?

Some code samples will be greatly appreciated.

Thanks :)

Answers


Can you try this

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

and into store: { ..., autoLoad: true }

I hope this helps. :) Ciao.


Need Your Help

r select values below and after a certain value in a dataframe

r time dataframe data.table xts

i have a question how to select certain values from a table. I have a table with times and values and i want to get the row below and after a certain time.

Compile to byte code takes up too much memory

python memory dictionary bytecode

I need to import a very large dictionary into python and I'm running into some unexpected memory bottlenecks. The dictionary has the form,