PDA

View Full Version : load store and refresh list problem



macs
17 Apr 2012, 4:34 AM
i use a store with a jsonp proxy that requests a json from my server. the store is set to autoload: true and hooked up with a listview. when the app launches the list is filled the the response as it should/ however when i then add a new item in the backend and refresh the list with the code shown below neither the store nor the list object contains the newly created entries. no error in the console. no loading mask. when i look at the response of my server the new item is there. hence it seems that after I call the load method on the store a new call is made by the proxy, but the data is not loaded in the store neither is the list refreshed. would anybody be so kind and an give me a hint about what i am doing wrong?


Ext.define('VB1.controller.ListController', {
extend: 'Ext.app.Controller',
config: {
refs: {
// We're going to lookup our view by xtype.
listView: 'listview',
refreshButtonTap: '#refreshbutton',
},
control: {
refreshButtonTap: {
onRefreshList: 'refreshList',
},
}
},
launch: function () {
this.callParent(arguments);
Ext.getStore('MyStore').addListener('load', 'recordLoaded', this);
},
refreshList: function () {
var loadedStore = Ext.getStore('MyStore').load();
console.log(loadedStore)
},
recordLoaded: function (record) {
var list = this.getListView();
list.refresh();
console.log(list)
}
});

AndreaCammarata
17 Apr 2012, 5:28 AM
Could you post your store configuration and the server side response before and after the new record has been added?

macs
17 Apr 2012, 5:41 AM
dear andrea, thanks for your quick response. i do not think the server response is the issue. it a 200 and when i simply relaunch the app after hitting refresh the new item is added. below is the code of my store/ i define it, hook it up to the list view, instantiate the view together with he store as xtype and add it to the viewport.



Ext.define('VB1.store.MyStore', {
extend: 'Ext.data.Store',
alias: 'widget.shopstore',
config: {
model: 'VB1.model.MyModel',
autoLoad: true,
proxy: {
type: 'jsonp',
url : 'myUrl.js',
noCache: false,
enablePagingParams: false,
reader: {
type: 'json',
rootProperty: 'array.resources'
},
},
},
});

//this is how i add the list with the store to the viewport

var listView = {
xtype: 'shoplistview',
store: {xtype: 'shopstore'},
}
Ext.Viewport.add(listView);

AndreaCammarata
17 Apr 2012, 5:53 AM
I guess the problem is due to the "noCache" param.
Try to remove it or set it to true, otherwise your request will be cached and your store will be no able to get the updated data.

macs
17 Apr 2012, 6:04 AM
the problem is that the api i am working with does not accept the extra parameter that is added when noCache is true is there a way to solve this inside the app?

AndreaCammarata
17 Apr 2012, 6:14 AM
You can change the cache param name changing the proxy "cacheString" config, but if the api doesn't accept any other param, them I think you need to fix this from the server side (if you are allowed).

macs
17 Apr 2012, 6:18 AM
unfortunately i am not. isn't there a way to set proxy data in the store manually and then refresh the list?

macs
17 Apr 2012, 7:02 AM
it is solved the api problem. the sore is loaded with the new data. however the list is still not filled with the new entries. the strange thing is that as i said when i inspect the store object, the new item is loaded. however when i inspect the list objects and its containing store object the new data item is not included. i also have the feeling that my store gets instantiated two times since i always find two requests in the console after the app has launched. do i do anything wrong here?

macs
18 Apr 2012, 3:05 AM
i found the solution to my problem. see here if you are interested: http://www.sencha.com/forum/showthread.php?196310-two-instances-of-the-same-store&p=782703#post782703