Sencha touch 将Sencha Touch 2 store(始终只存储一个型号)替换为直接链接到SessionStorage的型号
我定义了以下Sencha存储,它使用SessionStorage:Sencha touch 将Sencha Touch 2 store(始终只存储一个型号)替换为直接链接到SessionStorage的型号,sencha-touch,sencha-touch-2,Sencha Touch,Sencha Touch 2,我定义了以下Sencha存储,它使用SessionStorage: Ext.define('TestApp.store.SessionStore', { extend: 'Ext.data.Store', config: { model: 'TestApp.model.SessionStoreModel', autoLoad: true, autoSync: true, proxy: {
Ext.define('TestApp.store.SessionStore', {
extend: 'Ext.data.Store',
config: {
model: 'TestApp.model.SessionStoreModel',
autoLoad: true,
autoSync: true,
proxy: {
type: 'sessionstorage',
id: 'SessionStore'
}
}
});
此商店具有以下型号:
Ext.define('TestApp.model.SessionStoreModel', {
extend: 'Ext.data.Model',
config:{
identifier: {
type: 'uuid'
},
fields: [
{ name:'token', type:'string'},
{ name:'auth', type:'boolean', defaultValue: false }
]
}
});
想法是,
我将始终只有一个模型内,而不是更多
只为一个模型建立一个存储区似乎有些过分(我必须清除它,在使用它时计算它的索引)
在我看来,应该有一种方法让模型直接将数据保存到SessionStorage并引用它,而不是开发存储
这可以在Sencha Touch 2中完成吗
更新
以下是我所做的徒劳:
Ext.define('TestApp.model.TestModel', {
extend: 'Ext.data.Model',
config: {
identifier: {
type: 'uuid'
},
fields: [
{ name:'auth', type:'boolean', defaultValue: false }
],
proxy: {
type: 'sessionstorage'
}
}
});
保存模型数据:
// Test.
TestApp.model.TestModel.load(1, {
scope: this,
success: function(record, operation) {
console.log('TestModel read success');
console.log(record.get('auth'));
},
failure: function(record, operation) {
console.log('TestModel read failure');
},
callback: function(record, operation) {
console.log('TestModel read callback');
}
});
//测试
var testModel = Ext.create('TestApp.model.TestModel', {
auth: 'La Playa'
});
testModel.save({
scope: this,
success: function() {
console.log('TestModel success');
},
failure: function() {
console.log('TestModel failure');
},
callback: function() {
console.log('TestModel callback');
}
});
Reade模型数据:
// Test.
TestApp.model.TestModel.load(1, {
scope: this,
success: function(record, operation) {
console.log('TestModel read success');
console.log(record.get('auth'));
},
failure: function(record, operation) {
console.log('TestModel read failure');
},
callback: function(record, operation) {
console.log('TestModel read callback');
}
});
但它不起作用,无法从会话存储中读取这可以在Sencha Touch 2中完成
Ext.define('TestModel', {
extend: 'Ext.data.Model',
config: {
identifier: {
type: 'uuid'
},
fields: [
{name: 'token', type: 'string'},
],
proxy: {
type: 'sessionstorage'
}
}
});
var testModel = Ext.create('TestModel', {
token: 'Token'
});
var id;
testModel.save(function (record) {
id = record.getId();
console.log('id:' + record.getId());
});
TestModel.load(id, {
failure: function (record, operation) {
console.log('Failed...');
},
success: function (record, operation) {
console.log('It worked');
}
});
这是可行的,但是在创建之后使用“testModel”实例。但我无法在其他视图中引用此实例。它不起作用。模型加载函数是静态的,因此只要知道记录id,您就可以在任何地方调用它并检索记录。您可以在创建模型后使用Ext.ModelManager.getModel('TestModel')获取对该模型的引用。