PDA

View Full Version : Populate a Label with values



Nick334
7 Jul 2012, 1:19 PM
I am stuck with an issue for days. I am clueless how to solve this even-though i have read the same documents over and over again. I am beginner and i would consider it great if someone could help a beginner.



Ext.define('Ex.view.info', {
extend: 'Ext.window.Window',
alias: 'widget.info',
initComponent: function() {
var st = Ext.getStore('peopleinformation');
st.load();
this.items = [
{
xtype: 'label',
forId: 'myFieldId',
text: 'My Awesome Field',
name: 'personfirstname',
margins: '0 0 0 10'
}
];
this.callParent(arguments);
}});


I have added a label to a window, and i am trying to populate the label from the Store.


Ext.define('Ex.store.Info',{
extend:'Ext.data.Store',
model:'Ex.model.Info',
proxy: {
type: 'ajax',
url: '/info.php'
}
});

Model


Ext.define ('Ex.model.Info',{
extend: 'Ext.data.Model',
fields:['personfirstname']
});

The JSON that gets returned
[{"personfirstname":"shak"}]

Nothing gets displayed, and there's no errors thrown to the console. I am clueless.

scottmartin
8 Jul 2012, 2:45 PM
Have you considered using displayField to display data as a label?
You can also use label.setText('my new label');

Scott

sword-it
8 Jul 2012, 11:44 PM
Hi!

Is your store completely loaded when you are creating items for your window?
Ajax is asynchronous in nature, maybe your items are created before loading of store completed.

try this:-




store.load({
scope : YourScope,
callback: function(records, operation, success) {
//create or set your label text here
}
});