Javascript 让LocalStorageProxy与TreeStore一起工作
喂 我正在构建一个Sencha Touch iPhone应用程序,它使用了一个树孔,可以很好地与嵌套列表配合使用,但我遇到了麻烦 它需要一种方法来读取静态存储(TreeStore)中的数据,将其加载到localStorage中以使其可写,然后保存一些用户首选项。我发现localStorageProxy很可能就是我所需要的(我很欣慰地发现我不必手动序列化和反序列化JSON存储!)但是在阅读了关于它的文档并尝试了一些失败的事情之后,我不知所措 目前,它生成了localStorage…storage,但它是空的,我想这是因为除了执行Javascript 让LocalStorageProxy与TreeStore一起工作,javascript,sencha-touch,local-storage,extjs,Javascript,Sencha Touch,Local Storage,Extjs,喂 我正在构建一个Sencha Touch iPhone应用程序,它使用了一个树孔,可以很好地与嵌套列表配合使用,但我遇到了麻烦 它需要一种方法来读取静态存储(TreeStore)中的数据,将其加载到localStorage中以使其可写,然后保存一些用户首选项。我发现localStorageProxy很可能就是我所需要的(我很欣慰地发现我不必手动序列化和反序列化JSON存储!)但是在阅读了关于它的文档并尝试了一些失败的事情之后,我不知所措 目前,它生成了localStorage…storage,
app.stores.event_store.load()之外,我没有向其中加载任何内容代码>屏幕为空,控制台显示localStorage为空,没有错误
我的模型:
Ext.regModel('Events', {
fields: [
{name: 'text', type: 'string'},
{name: 'info', type: 'string'},
{name: 'attend', type: 'boolean', defaultValue: 'false'}
]
});
Ext.regModel('事件'{
字段:[
{name:'text',键入:'string'},
{name:'info',键入:'string'},
{name:'attain',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();
app.stores.event_store=新建Ext.data.TreeStore({
模型:“事件”,
根:数据,
storeId:'eventStoreId',
代理:{
类型:“localstorage”,
id:“事件处理”,
url:'store.js',
读者:{
键入:“树”,
root:'项目'
}
}
});
app.stores.event_store.load();
这可能源于对这些模型和商店如何相互作用缺乏基本的了解,但如果有人能提供帮助,好的业力将被送到你的路上
有关完整的应用程序,请访问
-fetimo树顶需要分层数据
var data= {
text: 'Groceries',
items: [{
text: 'Drinks',
items: [{
text: 'Water',
items: [{
text: 'Sparkling',
leaf: true
},{
text: 'Still',
leaf: true
}]
},{
text: 'Coffee',
leaf: true
}]
}]
}
但是LocalStorageProxy无法匹配此数据结构的模型
我将使用AJAX请求加载“store.js”文件,使用localStorage直接“存储”数据blob
Ext.Ajax.request({
url: 'store.js',
success: function(response, opts) {
localStorage.StoreJSBlob = response.responseText;
}
});
然后,您的商店将如下所示:
var store = new Ext.data.TreeStore({
model: 'Events',
root: localStore.StoreJSBlob,
proxy: {
type: 'ajax',
reader: {
type: 'tree',
root: 'items'
}
}
});
您只需将事件正确地链接在一起,因为异步调用可能会绊倒您我担心这是唯一的方法。真可惜。我花了很多时间让localStorage商店为我的基本列表工作!