PDA

View Full Version : Load event not firing...



CayIT
29 Jan 2010, 2:40 PM
Hi there,

I am trying to dynamically allocate some labels from a JsonStore to set field labels on a form. I have been debugging with firebug and it seems that my load event won't even fire. I have only been using ExtJS for a week so I am still pretty clueless with it. I'm hoping the problem is obvious, but my searches have yielded no positive results.

Here is the Json object that my store is consuming:
{"list": [
{"lblId": "addr1", "label": "Address"},
{"lblId": "addr2", "label": "Blank"},
{"lblId": "addr3", "label": "Blank"}
]}

Here is a snippit of my code:


var storelabels = new Ext.data.JsonStore( {
url : 'bq050c.form?action=label',
root : 'labels',
//autoload: true,
fields : [ 'lblId', 'label' ]
});

// set labels when load is fired
storelabels.on('load', function() {
alert('test');
Ext.getCmp("addr1").setFieldLabel(storelabels.getAt(0).get("label"));
});

// sets field label of form
Ext.override(Ext.form.Field, {
setFieldLabel : function(text) {
if (this.rendered) {
this.el.up('.x-form-item', 10, true).child('.x-form-item-label').update(text);
}
this.fieldLabel = text;
}
});The only way I have been able to successfully get my alert to show is by changing the event to 'beforeload.' When I do that however, I obviously have an error because the records don't exist yet.

Thanks in advance.

Cheers,

I



EDIT: Looks like I messed up the root on the Jsonstore. Fixed it and everything works now :)

Animal
30 Jan 2010, 12:51 AM
It's not loading.

http://www.extjs.com/deploy/dev/docs/?class=Ext.data.JsonReader&member=root

30 Jan 2010, 1:54 PM
I don't see where you're calling the store's load method. Are you sure you're even doing that?

CayIT
1 Feb 2010, 3:19 PM
Left that part out, but it was in the code.

Everything works fine now away. I figured out what I was doing wrong when I tried listening for loadexceptions from the store.

Cheers,
I

Mike Robinson
2 Feb 2010, 8:04 AM
Can you quickly summarize, for the rest of us, what it turned out you were doing wrong?

It helps (future readers) when a thread that reports a bug "comes to closure" about just what the problem was. (vs. "Never mind! I fixed it!")

CayIT
2 Feb 2010, 9:20 AM
I already edited into my original post how I was able to fix it, thanks.

Cheers,
Ira