vendredi 17 octobre 2014

Sencha touch, my Model fails to load. html5 SessionStorage as proxy

Hi, i am trying to use a Html5 Session Storage on my app, i created a store and a model for it, i can add records to the SessionStorage using my function onSetstore "in my controller below", when i check on google chrome Resources the session storage is set with Key=>values in, but i cant retrieve values cause my model cant load, the function myModelName.load just fails , please check my code and let me know whr m going wrong ..Thanks in advance

model



Code:



Ext.define('Mymdl.model.Products', { extend: 'Ext.data.Model',
id:'productsModel',
requires: [
'Ext.data.proxy.SessionStorage'
],
config: {
fields: [
{
name: 'brandName'
},
{
name: 'brandCat'
},
{
name: 'quantity'
}

],
proxy: {
type: 'sessionstorage',
id: 'products_info'
}

}

});

Store

Code:



Ext.define('Mymdl.store.Products', {
extend: 'Ext.data.Store',
requires: [
'Mymdl.model.Products','Ext.data.proxy.SessionStorage'
],
config: {
model: 'Mymdl.model.Products',
storeId: 'MymdlStore',
proxy: {
type: 'sessionstorage',
id: 'products_info'
}
}
});



controll


Code:



Ext.define("Mymdl.controller.Main", {
extend: "Ext.app.Controller",
requires:['Mymdl.model.Products','Mymdl.store.Products'],
config: {
refs: {
btnSetstore:'#btn_set_store',
btnGetstore:'#btn_get_store'


},

control: {
btnSetstore: {
tap: "onSetstore"
},
btnGetstore: {
tap: "onGetstore"
}
}
},
onSetstore: function(){

console.log('set store OK');
var UserStore = Ext.getStore('MymdlStore');
console.log('store is '+UserStore);
UserStore.load();
UserStore.add({
brandName: 'Nike Jordan',
brandCat: 'Sneakers',
quantity: '31'
});
UserStore.sync();
var modelData = UserStore.getData();
console.log('Array model :'+modelData);

},
onGetstore: function() {

console.log('get store OK');
//get Model
var mdl = Ext.ModelMgr.getModel('Mymdl.model.Products');
console.log('model is '+mdl);

mdl.load(124, {
scope: this,
success: function(model, opp) {
console.log('passed');
Ext.Msg.alert('Brand name is : ' + model.get('brandName'));
}


,
failure: function(record, opp) {
console.log('failed');
}
});

}
});





Sencha touch, my Model fails to load. html5 SessionStorage as proxy

Aucun commentaire:

Enregistrer un commentaire