PDA

View Full Version : Reader in .js file



tombal93
1 Aug 2010, 3:02 AM
I have my ui.js and .js file.

In my UI file i have a window with a form and i need a jsonreader but i don't know how to do with Designer.

I manually add the reader and it works but i'd prefer not to insert it manually because each time i modify my UI i need to add the reader.

How can i add the reader into the .JS file ??



Categorie_fenetreUi = Ext.extend(Ext.Window, {
title: 'Modification de la catégorie',
layout: 'form',
padding: 5,
buttonAlign: 'center',
height: 220,
autoDestroy: true,
modal: true,
border: true,
width: 400,
id: 'Categorie_fenetre',
initComponent: function() {
this.items = [
{
xtype: 'form',
padding: 5,
unstyled: true,
headerAsText: false,
buttonAlign: 'center',
border: false,

////////////// ADDED MANUALLY ///////////////////////////
reader : new Ext.data.JsonReader({
fields: [
{name: 'RUBRIQUE_FR', type:'string'},
{name: 'RUBRIQUE_AN', type: 'string'},
{name: 'RUBRIQUE_JP', type: 'string'},
]
}),
////////////// END ADDED MANUALLY //////////////////////

animCollapse: false,
layout: 'form',
ref: 'F_catedit',
id: 'F_catedit',
items: [
{
xtype: 'textfield',
value: '',
readOnly: true,
fieldLabel: 'ID',
ref: '../ID_RUBRIQUE',
id: 'ID_RUBRIQUE'
},
{
xtype: 'textfield',
allowBlank: false,
fieldLabel: 'Français',
ref: '../RUBRIQUE_FR',
id: 'RUBRIQUE_FR'
},
{
xtype: 'textfield',
allowBlank: false,
fieldLabel: 'Anglais',
ref: '../RUBRIQUE_AN',
id: 'RUBRIQUE_AN'
},
{
xtype: 'textfield',
allowBlank: false,
fieldLabel: 'Japonais',
ref: '../RUBRIQUE_JP',
id: 'RUBRIQUE_JP'
}
],
fbar: {
xtype: 'toolbar',
ref: '../M_catedit',
id: 'M_catedit',
items: [
{
xtype: 'button',
text: 'Modifier',
type: 'button',
ref: '../../B_submit',
id: 'B_submit'
},
{
xtype: 'button',
text: 'Annuler',
type: 'button',
ref: '../../B_reset',
id: 'B_reset'
}
]
}
}
];
Categorie_fenetreUi.superclass.initComponent.call(this);
}
});



Here is my JS file :



Categorie_fenetre = Ext.extend(Categorie_fenetreUi, {

initComponent: function() {
Categorie_fenetre.superclass.initComponent.call(this);

// click sur le bouton ANNULER on ferme la fenetre
this.B_reset.on('click', this.fermeture, this);

},

// fonction pour fermer la fenêtre
fermeture: function() {
this.close();
}



});


Thanks for your help

jarrednicholls
1 Aug 2010, 6:18 AM
Hi tombal93,

There is no ability to add a reader configuration to your FormPanel directly at this time. However, in your case you don't even need to. The BasicForm/FormPanel has built-in support for reading JSON to load data into the form for a "load()" operation. See the Action.Load documentation for more details on the structure that your JSON response should be in: http://www.sencha.com/deploy/dev/docs/?class=Ext.form.Action.Load (see success and failure response examples)

Hope that helps.

tombal93
1 Aug 2010, 9:59 PM
Thanks, the perfect solution, great as always !