让 LocalStorageProxy 与 TreeStore 一起使用
你好,
我正在构建一个 Sencha Touch iPhone 应用程序,它使用 TreeStore,它与 NestedList 配合得很好,但我遇到了困难。
它需要一种方法来读取静态存储(TreeStore)中的数据,将其加载到 localStorage 中,使其可写,然后保存一些用户首选项。我发现 localStorageProxy 很可能就是我所需要的(我很欣慰地发现我不必手动序列化和反序列化 JSON 存储!)但是在阅读了它的文档并尝试并失败了一些事情之后,我我不知所措。
就目前情况而言,它生成了 localStorage… 存储,但它是空的,我猜这是因为我没有加载任何东西到其中,但在执行 app.stores.event_store.load();
时,屏幕是空白,控制台显示 localStorage 为空,没有错误。
我的模型:
Ext.regModel('Events', { fields: [ {name: 'text', type: 'string'}, {name: 'info', type: 'string'}, {name: 'attend', type: 'boolean', defaultValue: 'false'} ] });
我的商店:
app.stores.event_store = new Ext.data.TreeStore({ model: 'Events', root: data, storeId: 'eventStoreId', proxy: { type: 'localstorage', id: 'eventsAttending', url: 'store.js', reader: { type: 'tree', root: 'items' } } }); app.stores.event_store.load();
这可能源于对这些模型和商店如何相互作用缺乏基本的了解,但如果有人可以提供帮助,良好的业力将会送给你。
完整的应用程序可以在 它的 GitHub 存储库 中找到。
-费蒂莫
Hullo there,
I am building a Sencha Touch iPhone app that utilises a TreeStore which works nicely with a NestedList but I've hit a wall.
It needs a way to read data in a static store (the TreeStore), load it into localStorage so it's writable and then save some user preferences. I've figured out that the localStorageProxy is most likely what I need (I was relieved to discover I didn't have to serialise and deserialise the JSON store manually!) but after reading the documentation on it and trying and failing a few things I'm at a loss.
As it stands, it generates the localStorage… storage but it's empty, this I guess is because I haven't loaded anything into it but on doing app.stores.event_store.load();
the screen is blank and Console shows that the localStorage is empty with no errors.
My model:
Ext.regModel('Events', { fields: [ {name: 'text', type: 'string'}, {name: 'info', type: 'string'}, {name: 'attend', type: 'boolean', defaultValue: 'false'} ] });
My store:
app.stores.event_store = new Ext.data.TreeStore({ model: 'Events', root: data, storeId: 'eventStoreId', proxy: { type: 'localstorage', id: 'eventsAttending', url: 'store.js', reader: { type: 'tree', root: 'items' } } }); app.stores.event_store.load();
It probably stems from a lack of a fundamental understanding of how these models and stores interact but if anyone could help, good karma will be sent your way.
The full application can be found at it's GitHub repo.
-fetimo
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
TreeStore 需要分层数据
,但 LocalStorageProxy 无法匹配此数据结构的模型。
我将使用 AJAX 请求来加载“store.js”文件,并使用 localStorage 直接“存储”数据 blob。
那么你的商店将看起来像这样:
你只需要正确地将事件链接在一起,因为异步调用可能会让你陷入困境
The TreeStore expects hierarchical data
But the LocalStorageProxy is unable to match the model for this data structure.
I would use an AJAX request to load the "store.js" file using the localStorage directly to "store" the data blob.
then your store will look something like this:
You just have to chain the events together correctly, as the async calls could trip you up