PDA

View Full Version : Filling textfield with value of a json store



blade226
14 Feb 2013, 12:41 AM
Hi,

i want to fill a textfield with a value of a store. I tried different ways, but without success.

Here are some attempts:

items: [{
fieldLabel: 'Name',
name: 'first',
allowBlank: false,
value: mystore.name
},]


or

tr_stamm.getForm().findField('first').setValue(mystore.name);
or

var textfield_tr_name = Ext.create('Ext.form.TextField', {
fieldLabel: 'Name',
name: 'first',
allowBlank: false

});
textfield_tr_name.setValue(mystore.name);


Can someone help me?

vadimv
14 Feb 2013, 1:08 AM
what's under 'mystore' ? , also if the field is in a form you can set all default values with form's API.

blade226
14 Feb 2013, 1:11 AM
mystore is a store, which is filled with json-variables



var mystore = Ext.create('Ext.data.Store', {
// destroy the store if the grid is destroyed
autoDestroy: true,
autoSync: true,

model: 'Employee_traeger',
proxy: {
type: 'ajax',
api: {
read: "includes/tr_stamm.php?pid="+sub,
create: "includes/tr_stamm.php?pid="+sub+"&anspr=create",
update: "includes/tr_stamm.php?pid="+sub+"&anspr=update",
destroy: "includes/tr_stamm.php?pid="+sub+"&anspr=destroy",

},
reader: {
type: 'json',
successProperty: 'success',
//root: 'data',
messageProperty: 'message',
listeners: {
create: function(mystore, t, operation, opts) {
if (operation == Ext.data.Model.COMMIT) {
mystore.reload();
}
}
}

blade226
14 Feb 2013, 1:33 AM
I found a problem.

the variable mystore.name is undefined.
How can a change this?

vadimv
14 Feb 2013, 1:37 AM
The you should look better in docs, to get the value of a field you have to do it trough a record(Ext.data.Model, in your case is Employee_traeger) or trough store's API get/find/filter methods.

vadimv
14 Feb 2013, 1:38 AM
I found a problem.

the variable mystore.name is undefined.
How can a change this?
Already wrote, I recommend you to check the docs and examples on how to use stores, records and bind a record to a form

blade226
14 Feb 2013, 2:04 AM
I found nothing in the api of store or i don't understand.

I tried it so:
var tr_name;

mystore.load(function(){
tr_name = this.getAt(0).get('name')
console.log(tr_name);
});
or so

mystore.load({
scope: this,
callback: function (records, operation, success) {
tr_name = mystore.getAt(0).get('name');
} });

In the store.load i have the data of tr_name, but in the form the value is empty!
How can I make sure that the variable is also available in the form?

blade226
14 Feb 2013, 2:41 AM
I have the solution:


mystore.load({
scope: this,
callback: function (records, operation, success) {
tr_stamm.getForm().findField('first').setValue(mystore.getAt(0).get('name'));
} });

vadimv
14 Feb 2013, 8:08 AM
better:



mystore.load({
scope: this,
callback: function (records, operation, success) { tr_stamm.getForm().findField('first').setValue(records[0].get('name'));}
});

EDIT: oh boy, was a hint I thought you will understand....reedited the code
or just:


tr_stamm.getForm().loadRecord(records[0]);}

blade226
14 Feb 2013, 10:26 PM
So I can get only the data that is placed in a form. But I would add values.

Or you can complete your code.