Reputation: 16849
I need to know how to populate a Label
with values from Store
. In my Model
i have defined a field called bookname
. and i need to populate this label with the Book Name.
I know how to do this for a Grid, but don't know how to do it for a Label
or a Textfield
.
In Grid;
{ text: "Book Name", dataIndex: 'bookname'},
But, how can we add values to Label and textfields.
UPDATE
i am still having the problem. I am unable to set the values to the Label. (after loading it from STORE). The Label gets displayed but it doesn't get populated with the value that it got from STORE. There's no error as such.
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);
}
});
Upvotes: 0
Views: 6607
Reputation: 1897
For just setting a value for label , you can use setText method described in label http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Label-method-setText
yourLabel.setText('value');
For textField - http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.field.Text-method-setValue
UPDATE:
// in your store
proxy: {
type: 'ajax',
url: 'you url',
method: 'GET',
headers: { 'Content-Type': 'application/json' }, //your response type like xml, json
reader: { type: 'json',
getResponseData: function (response) {
var data = Ext.decode(response.responseText);
//loop here , if more labels are there
// get the object referance of label and update that
}
}
UPDATE: do you tried:
text: st.yourFieldName,
Upvotes: 2
Reputation: 12613
Ext 4.1 introduced setFieldLabel()
on Ext.form.Labelable
which is mixed into Ext.form.field.Base
, making it available in Ext.form.field.Text
.
Thus you can call myTextField.setFieldLabel("My Label Text")
Upvotes: 0
Reputation: 17860
Various fields
are usually combined as items in form
- (see http://docs.sencha.com/ext-js/4-0/#!/api/Ext.form.Panel). Form has a method getForm().loadRecord(model)
to load data from the model (record in your store) to all fields within the form.
PS: Looks like you haven't gone through Sencha guides (http://docs.sencha.com/ext-js/4-0/#!/guide) as I advised you on your other questions. You still don't have general idea of how things work.
Upvotes: 0