0
嗨,我想在我的應用程序中使用JavaScript會話存儲在sencha觸摸模型,在互聯網上長時間搜索後,我沒有得到幸運,請幫助,如果可以,謝謝。 這是我的代碼到目前爲止。
我的控制器的onStorage功能工作,getStorage usession.load加載失敗,那是我又立刻陷入
Sencha Touch sessionstorage,保存和檢索
Ext.define('SideMenu.controller.Menu', {
extend: 'Ext.app.Controller',
currView:'home',
requires: ['SideMenu.model.Mymdl'],
config: {
refs: {
btn_localstore:'#btn_localstore',
btn_getlocalstore:'#btn_getlocalstore'
}
control: {
btn_localstore:{
tap: 'onStorage'
},
btn_getlocalstore:{
tap: 'getStorage'
},
},
onStorage:function(){
//create model and store data
var myMod = Ext.create('SideMenu.model.Mymdl',{
brandName:'Nike Jordan',
brandCat:'Sneakers'
});
myMod.save({
success:function(res){
console.log('saved to model : '+res.get('brandName'));
}
});
},
getStorage:function(){
var usession = Ext.ModelMgr.getModel('SideMenu.model.Mymdl');
console.log('model is :'+usession);
usession.load(0, {
scope: this,
success: function(model, opp) {
console.log('passed '+model.get('brandCat'));
},
failure: function(record, operation) {
console.log('failed : '+operation);
// Ext.Viewport.setMasked(false);
//====================================================
// alert('could not get session details');
//====================================================
}
});
}
}
我的模型
Ext.define('SideMenu.model.Mymdl', {
extend : 'Ext.data.Model',
xtype : 'Mymdl',
requires:['Ext.data.proxy.SessionStorage'],
id : 'Mymdl',
config: {
fields: [
'brandName',
'brandCat'
]
,
proxy : {
type: 'localstorage',
id : 'mymdl'
}
}
});
我app.js我排除了其他不需要的東西dts
models: ['Mymdl'],
views: ['Main', 'Home'],
controllers: ['Menu'],
launch:function()
{
Ext.create('SideMenu.model.Mymdl');
}
你的回答將不勝感激,謝謝
傑夫馬丁,你剛剛救了我的命人,非常感謝,我爲此掙扎了兩天......讓一個Sencha無法幫助我的人,不幸的是我無法提升我低聲譽的CS。 .bt thnks bru,ura genius man – 2014-10-20 06:48:28
還有一件事,當我保存模型時,如何設置id值。 – 2014-10-20 06:59:27
模型ID屬性是自動創建的。您可以使用model.set('id,[value])來設置值。 – 2014-10-21 10:45:40