PDA

View Full Version : data.Store not loading altho FB shows the request



oth
19 Aug 2007, 8:19 AM
Greetings,

So as the title says I have an issue with Ext.data.Store where it's not loading the data, but firebug shows the request and response and there is data returned from the server.

this is the code:


prepareProductEdit: function() {

productData = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'/admin/products/read/'}),
reader: new Ext.data.JsonReader({},['id','active','selected','featured', 'name','code','intro','price',
'price_promo','description','photo','status','availability']),
remoteSort: false
});

productData.on('load', function() {
console.log(productData);
dataRec = productData.getAt(0);
productForm.findField('id').setValue(dataRec.data['id']);
//ifId.setValue(infoData.getAt(0).data['id']);
productForm.findField('active').setValue(dataRec.data['active']);
productForm.findField('featured').setValue(dataRec.data['featured']);
productForm.findField('selected').setValue(dataRec.data['selected']);
productForm.findField('name').setValue(dataRec.data['name']);
productForm.findField('code').setValue(dataRec.data['code']);
productForm.findField('intro').setValue(dataRec.data['intro']);
productForm.findField('price').setValue(dataRec.data['price']);
productForm.findField('price_promo').setValue(dataRec.data['price_promo']);
productForm.findField('status').setValue(dataRec.data['status']);
productForm.findField('availability').setValue(dataRec.data['availability']);
productForm.findField('description').setValue(dataRec.data['description']);
Ext.get('product_photo').set({src:'/img/' + dataRec.data['photo']});

});
productId = productsGrid.getSelectionModel().getSelected().data.id;
productData.load({params: {id: productId}});
}

First of all console.log(productData); shows in Firebug that ProductData.data is empty. the javascript console says dataRec has no properties. along with some ugly error
[Exception... "'Permission denied .. HTMLDivElement.nodeType' when calling method: [nsIDOMEventListener::handleEvent]" nsresult: "0x8057001e (NS_ERROR_XPC_JS_THREW_STRING)" location: "<unknown>" data: no]

Anyone knows what might cause this ? I have used on('load',..) successfully before

Thanks

oth
20 Aug 2007, 7:18 AM
It seems weird to me that productData.data is empty within productData.on('load', normally this callback is called when data is loaded.. anyone has a hint ?

Animal
20 Aug 2007, 7:31 AM
What does your Json look like?

oth
20 Aug 2007, 12:49 PM
{"id":"11","name":"KIPSTA R 300 mousse","code":"10579","intro":"Con","description":"TOUCHER DE BALLE

:\r\n\r\nbonne accroche gr","price":"280.0000","price_promo":"0.0000","active":"1","category_id":"3"

,"status":"N","featured":"1","selected":"1","photo":"10579.jpg","availability":"B","slug":"","sort_order"

:"0","created":"0000-00-00 00:00:00","modified":"0000-00-00 00:00:00"}

devnull
20 Aug 2007, 1:11 PM
To start with, your data store should be more like this:


productData = new Ext.data.Store({
proxy: new Ext.data.HttpProxy({url:'/admin/products/read/'}),
reader: new Ext.data.JsonReader({
id: 'id',
root: 'somevalue'
},['id','active','selected','featured', 'name','code','intro','price',
'price_promo','description','photo','status','availability']),
remoteSort: false
});

and your json:


{"somevalue":[{"id":"11","name":"KIPSTA R 300 mousse","code":"10579","intro":"Con","description":"TOUCHER DE BALLE

:\r\n\r\nbonne accroche gr","price":"280.0000","price_promo":"0.0000","active":"1","category_id":"3"

,"status":"N","featured":"1","selected":"1","photo":"10579.jpg","availability":"B","slug":"","sort_order"

:"0","created":"0000-00-00 00:00:00","modified":"0000-00-00 00:00:00"}]}

'somevalue' being an array of array's basically.

oth
20 Aug 2007, 5:00 PM
Hey, thanks devnull wrapping the data into an array works. Makes sense too since getAt(0) is looking at the first record. It's weird tho, I have another place where it's working with that. oh well. thanks again