正在为嵌套列表设置LocalStorage存储

Setting LocalStorage store for nested list

本文关键字:设置 LocalStorage 存储 列表 嵌套      更新时间:2023-09-26

我已经创建了一个本地存储库,并按照本教程将演示值存储在其中:

http://sureshdotariya.blogspot.com/2013/03/understanding-local-storage-proxy-in.html

这一切都很好,我在chrome中查看了资源中的存储数据,它就在那里,当我加载页面时,它加载得很好,没有错误,但没有显示任何数据,这是我的视图代码:

Ext.define('MyTest.view.SearchPanel', {
    extend: 'Ext.Panel',
    xtype: 'searchpanel',
    config: {
        layout: 'fit',
        items: [
        {
            xtype: 'nestedlist',
            title: 'Search Results',
            displayField: 'Name',
            store: {     
                storeId: 'UserStore',
                fields: ['Name']
            },
        }]
    }
});

我在这里错过了什么?我可以使用本地存储存储作为嵌套列表的存储吗?如果是的话,那么为什么它显示"没有找到项目",我在app.js中添加了商店,我试着在这个视图中要求它,但没有成功。

谢谢你的帮助。

Ext.dataview.NestedList需要Ext.data.TreeStore而不是Ext.data.Store(在您提供的示例URL中(。

Ext.data.TreeStore中需要rootdefaultRootProperty配置,项中有leaf属性。

当然,您可以在Ext.data.TreeStore中将Ext.data.proxy.LocalStorage设置为代理,请尝试使用以下代码:

Ext.define('ListApp.model.User', {
     extend: 'Ext.data.Model',
     config: {
         fields: [{
             name: 'text',
             type: 'string'
         }]
     }
 });
Ext.define('App.store.User', {
    config: {
        model: 'ListApp.model.User',
        defaultRootProperty: 'items',
        root: data
        proxy: {
            type: 'localstorage',
            id: 'UserInfo'
       }
    }
});