Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
99
rated 0 times [  105] [ 6]  / answers: 1 / hits: 15630  / 13 Years ago, thu, june 2, 2011, 12:00:00

How to populate form with JSON data using data store? How are the textfields connected with store, model?



Ext.define('app.formStore', {
extend: 'Ext.data.Model',
fields: [
{name: 'naziv', type:'string'},
{name: 'oib', type:'int'},
{name: 'email', type:'string'}
]
});

var myStore = Ext.create('Ext.data.Store', {
model: 'app.formStore',
proxy: {
type: 'ajax',
url : 'app/myJson.json',
reader:{
type:'json'
}
},
autoLoad:true
});

Ext.onReady(function() {


var testForm = Ext.create('Ext.form.Panel', {
width: 500,
renderTo: Ext.getBody(),
title: 'testForm',
waitMsgTarget: true,
fieldDefaults: {
labelAlign: 'right',
labelWidth: 85,
msgTarget: 'side'
},
items: [{
xtype: 'fieldset',
title: 'Contact Information',
items: [{
xtype:'textfield',
fieldLabel: 'Name',
name: 'naziv'
}, {
xtype:'textfield',
fieldLabel: 'oib',
name: 'oib'
}, {
xtype:'textfield',
fieldLabel: 'mail',
name: 'email'
}]
}]

});

testForm.getForm().loadRecord(app.formStore);
});


JSON



[
{naziv:Lisa, oib:2545898545, email:[email protected]}
]

More From » json

 Answers
9

The field names of your model and form should match. Then you can load the form using loadRecord(). For example:



var record = Ext.create('XYZ',{
name: 'Abc',
email: '[email protected]'
});
formpanel.getForm().loadRecord(record);


or, get the values from already loaded store.


[#91900] Wednesday, June 1, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
isham

Total Points: 69
Total Questions: 86
Total Answers: 86

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
;