2012-03-30 96 views
1

我正在Sencha Touch 2中使用PhoneGap包装器构建应用程序。 我在MVC模式的编码,这里是应用程序的Web服务器的链接(调试运行):http://nqatalog.negroesquisso.pt/APP/登录:用户名:1​​,密码:1NestedList不会呈现

我有一个嵌套列表与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' 
     } 
    } 
} 
}); 

查看

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() {} 
}); 

这个嵌套列表呈现为空(正如你可以看到和调试,如果你想在上面的链接)

谢谢你的时间。

* EDIT(数据/ 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

里卡多,

我只是有这个同样的问题,我又看看煎茶文档中的NestedList sample。我注意到所有数据和数据集合都具有相同的键(项目/文本)。我试着调整我的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' 
     } 
    } 
}); 

编辑

它看起来像你的模型定义有单词 “condig”而不是“配置”。此外,它看起来好像NestedList需要使用“项目”的集合和“文本”的描述。

+0

嗨。我在我的Leftmenu视图中添加了'layout:fit'。现在列表树呈现,但没有文字apears。检查它在我的网络服务器。 – Ricardo 2012-03-30 16:56:39

+0

用它更新了原文。谢谢你的时间。 – Ricardo 2012-03-30 17:07:48

+0

我只是将关键字“名称”更改为“文本”,它的工作原理。它看起来像钥匙必须特别是集合的“项目”和名称或描述的“文本”。请确保您在模型定义中的字段列表中更改它。 – 2012-03-30 17:15:40

0

我花了很多时间处理这个相同的问题,直到我意识到我忘记了将新的商店(例如嵌套菜单)列入app.js应用程序的商店数组中。