NestedList не будет отображаться - PullRequest
1 голос
/ 30 марта 2012

Я создаю приложение в Sencha Touch 2, используя обертку PhoneGap. Я кодирую в модели MVC, вот ссылка на приложение в веб-сервере (для отладки): http://nqatalog.negroesquisso.pt/APP/ ВХОД: пользователь: 1, пароль: 1

У меня есть вложенный список с TreeStore для загрузки его данных и файл .json с данными.

Модель

Ext.define('APP.model.menuitem',{
                extend: 'Ext.data.Model',
                condig: {
                    fields: ['id', 'name', 'description', 'items']
                }
            });

Магазин

Ext.define('APP.store.nestedmenu', {
extend: 'Ext.data.TreeStore',

config: {
    model: 'APP.model.menuitem',

    autoLoad: true,

    proxy: {
        type: 'ajax',
        url: 'data/menu.json',
        reader: {
            type: 'json',
            rootProperty: 'items'
        }
    }
}
});

View

Ext.define('APP.view.MenuNestedList', {
extend: 'Ext.dataview.NestedList',
xtype: 'menunestedlist',
id: 'debug',

config: {
    store: 'nestedmenu'
},
});

Другой вид, вызывающий предыдущий

Ext.define("APP.view.Leftmenu", {
extend: 'Ext.Panel',
xtype: 'leftmenu',

config: {

    items: [
        {
            xtype: 'menunestedlist'
        }
    ],


    listeners: { 
        painted: function () {


        }
    },
},

onleafitemtap: function() {}
});

Этот вложенный список отображается пустым (как вы можете видеть и отлаживать, если хотите по ссылке выше)

Спасибо за ваше время.

* РЕДАКТИРОВАТЬ (data / menu.json)

{
"items": [
    {
        "id": 1,
        "name": "Section #1",
        "description": "Lorem ipsum dolor sit",

        "items": [
            {
                "id": 8,
                "name": "Product #1",
                "description": "Lorem ipsum dolor sit",
                "leaf": true
            },
            {
                "id": 9,
                "name": "Product #2",
                "description": "Lorem ipsum dolor sit",
                "leaf": true
            }
        ]
    },        
    {
        "id": 2,
        "name": "Section #2",
        "description": "Lorem ipsum dolor sit",

        "items": [
            {
                "id": 3,
                "name": "Section #3",
                "description": "Lorem ipsum dolor sit",

                "items": [
                    {
                        "id": 10,
                        "name": "Product #3",
                        "description": "Lorem ipsum dolor sit",
                        "leaf": true
                    },
                    {
                        "id": 11,
                        "name": "Product #4",
                        "description": "Lorem ipsum dolor sit",
                        "leaf": true
                    }
                ]
            },
            {
                "id": 4,
                "name": "Section #4",
                "description": "Lorem ipsum dolor sit",

                "items": [
                    {
                        "id": 12,
                        "name": "Product #5",
                        "description": "Lorem ipsum dolor sit",
                        "leaf": true
                    },
                    {
                        "id": 13,
                        "name": "Product #6",
                        "description": "Lorem ipsum dolor sit",
                        "leaf": true
                    }
                ]
            },
            {
                "id": 5,
                "name": "Section #5",
                "description": "Lorem ipsum dolor sit",

                "items": [
                    {
                        "id": 14,
                        "name": "Product #7",
                        "description": "Lorem ipsum dolor sit",
                        "leaf": true
                    }
                ]
            },
            {
                "id": 6,
                "name": "Section #6",
                "description": "Lorem ipsum dolor sit",

                "items": [
                    {
                        "id": 15,
                        "name": "Product #8",
                        "description": "Lorem ipsum dolor sit",
                        "leaf": true
                    },
                    {
                        "id": 16,
                        "name": "Product #9",
                        "description": "Lorem ipsum dolor sit",
                        "leaf": true
                    },
                    {
                        "id": 17,
                        "name": "Product #10",
                        "description": "Lorem ipsum dolor sit",
                        "leaf": true
                    }
                ]
            }
        ]             
    },
    {
        "id": 7,
        "name": "Section #7",
        "description": "Lorem ipsum dolor sit",

        "items": [
            {
                "id": 18,
                "name": "Product #11",
                "description": "Lorem ipsum dolor sit",
                "leaf": true
            },
            {
                "id": 19,
                "name": "Product #12",
                "description": "Lorem ipsum dolor sit",
                "leaf": true
            },
            {
                "id": 20,
                "name": "Product #13",
                "description": "Lorem ipsum dolor sit",
                "leaf": true
            }
        ]
    }
]       
}

Ответы [ 2 ]

2 голосов
/ 30 марта 2012

У меня была такая же проблема, и я еще раз взглянул на образец NestedList в документации Sencha.Я заметил, что все данные и коллекции данных имеют одинаковые ключи (элементы / текст).Я попытался настроить свой ответ JSON и обнаружил, что он работает.Вот мой код:

JSON ОТ PHP

{
    "items":
    [{
            "text":"Other",
            "items":
            [{
                    "text":"Employee IDs",
                    "leaf":"true"
            }]
    }]
}

JAVASCRIPT

Ext.define('ListItem', {
    extend: 'Ext.data.Model',
    config: {
        fields: ['text']
    }
});

var treeStore = Ext.create('Ext.data.TreeStore', {
    model: 'ListItem',
    defaultRootProperty: 'items',
    proxy: {
        type: 'ajax',
        url: 'data/get_sections.php',
        reader: {
            type: 'json',
            rootProperty: 'items'
        }
    }
});

РЕДАКТИРОВАТЬ

Похоже, в определении вашей модели вместо слова "config" есть слово "condig".Кроме того, создается впечатление, что NestedList требует использования «элементов» для коллекций и «текста» для описаний.

0 голосов
/ 09 июня 2012

Я провел много времени с этой же проблемой, пока не понял, что забыл указать свой новый Store (например, nestedmenu) в массиве store для приложения в app.js.

...