使用sencha touch,我想将我的数组列表数据存储在localStorage中,如图所示。如下使用sencha touch在localStorage中存储数组数据对象
我简单的存储数据,如日期,编号,名称中的localStorage在图书城刷新功能显示在图像
onStore刷新功能。但是找不到将arrayObject直接存储到localStorage的方式。
使用sencha touch,我想将我的数组列表数据存储在localStorage中,如图所示。如下使用sencha touch在localStorage中存储数组数据对象
我简单的存储数据,如日期,编号,名称中的localStorage在图书城刷新功能显示在图像
onStore刷新功能。但是找不到将arrayObject直接存储到localStorage的方式。
我不知道我完全理解你的问题..
如果你想店本地商店中的JavaScript对象,可以通过使用将javascript对象转换为字符串来实现方法。
var testString = JSON.stringify(testObj); //Converts testObject to Json string.
localStorage.testString = testString; // Stores testString into local storage.
您可以从本地存储获得的TestString,它通过
var testObj = JSON.parse(localStorage.testString);
转换为JavaScript对象或者你可以使用
Ext.encode(); // Encodes an Object, Array to String.
Ext.decode(); // Decodes (parses) a JSON string to an object.
你可以存储完整的对象,但如果你只是想存储主题,那么你需要创建新的模型。 定义了一个存储主题的模型,或者您可以存储您获取的完整对象。
Ext.define('Demo.model.Subjects', {
extend: 'Ext.data.Model',
config: {
fields: [
{ name: 'id', type: 'int' },
{ name: 'Subjects', type: 'auto' }
]
}
});
定义本地存储
Ext.define('Demo.store.MySubjectLocalStore', {
extend: 'Ext.data.Store',
config: {
storeId: 'mySubjectLocalStore',
model: 'Demo.model.Subjects',
autoLoad: true,
clearOnPageLoad: true,
proxy: {
type: 'localstorage',
id: 'demo-mySubjects-local-store'
}
}
});
将数据存储在本地存储
var subjectsLocal = Ext.getStore('mySubjectLocalStore');
//loop to get your subjects array from main Object then add each array to localstore
//loop start
var subjects = //get it from parent object inside loop
var subjectsModel = Ext.create('Demo.model.Subjects', {
Subjects : subjects,
id: //use integer so that you can get by this id when you retrive it
});
subjectsLocal.add(subjectsModel);
//loop End
subjectsLocal.sync();
其实我创造我的商店和模型作为参考从这个例子。 http://stackoverflow.com/questions/14797465/sencha-store-and-model-set-up-for-use-with-json 所以我有2个ListViews。其中一个视图与BookStore和第二个ListView与ProductList Store连接。 我的Ajax请求将由BookStore调用,并在其上载入我将所有数据设置为Product Store。 现在我的bookStore数据存储在localstorage中,但productList Data(SubjectList)无法保存。 –