PDA

View Full Version : Ext.List Error after updating store



multivan
30 Nov 2010, 10:48 AM
I get an error after selecting an item of a list "TypeError: Result of expression 'o' [undefined] is not an object (sencha-touch-debug-w-comments.js), when the store is refreshed by a JSONP-request. The error occurs, after the messagebox is quittet with ok. After that, the item is not selected.

When I populate the store directly, everything s ok and the item is selected.

What is my mistake?

I have a model:


Ext.regModel('Direction', {
fields: ['shade_depth', 'shade_direction']
});

a store:
var store = new Ext.data.JsonStore({
model: 'Direction'
});

the refresh-function:
var refresh = function() {
Ext.util.JSONP.request({
url: 'getDirection.php',
params: {InitColor:param_InitHair},
callbackKey: 'callback',
callback: function(data) {
data = data.results;
DirectionList.update(data);
}
});
};

an the Ext.List:
DirectionList = new Ext.List(
{
itemTpl: '{shade_depth}',
store: store
});
DirectionList.addListener('itemtap', function () {alert('tap');});

evant
30 Nov 2010, 2:44 PM
Your data could be wrong, it's difficult to say in an isolated context.

multivan
1 Dec 2010, 2:15 AM
I have checked the output from the php-file. I have call it in the browser with "getDirection.php?InitColor=3" and with the parameter from the JSONP.request "getDirection.php?InitColor=1&callback=Ext.util.JSONP.callback". I got exactly the same result, except that in the JSONP.callback the data is put into Ext.util.JSONP.callback( ... ).

Here is the Script, that has my problem:



var param_InitHair;

Ext.setup({
glossOnIcon: false,
onReady: function() {

Ext.regModel('Direction', {
fields: ['shade_depth', 'shade_direction']
});

var store = new Ext.data.JsonStore({
model: 'Direction',
proxy: {
type: 'ajax',
url : 'getDirection.php?InitColor=1',
reader: {
type: 'json',
root: 'results'
}
},
autoLoad: true
});

DirectionList = new Ext.List({
itemTpl: '{shade_depth}',
store: store
});

DirectionList.addListener('itemtap', function () {alert('tap');});

var MyButton = new Ext.Button (
{
text: 'Refresh',
ui: 'normal',
cls: 'mybutton',
handler: function(button, event) {
param_InitHair = 1;
refresh();
alert('REFRESHED!');
}
});

var panel = new Ext.Panel({
fullscreen: true,
layout: 'fit',
items: [MyButton, DirectionList]
});
}
});

var refresh = function() {
Ext.util.JSONP.request({
url: 'getDirection.php',
params: {InitColor:param_InitHair},
callbackKey: 'callback',
callback: function(data) {
data = data.results;
DirectionList.update(data);
}
});
};