PDA

View Full Version : best way to load data from store to Ext.Window?



m0e
8 Jan 2014, 4:51 PM
Hi everyone,

I'm currently trying to load data from my store into a text box within a ext.window.

I'm having a few problems, was wondering if someone could shed some light on the situation. I don't expect answers but if someone has had similar problems and can direct me to the appropriate resources that would be greatly appreciated.

Background of the app: The user clicks the 'edit' button on main page. an ext.window pops up with a bunch of fields, i'm trying to populate all those fields. To populate them i've got the main page sending through the the row ID to the jsp page. the jsp page then retrieves the data and generates a JSON response based on the ID provided.

My problems:
1. I'm not sure if the data is loading properly in the store. I've looked in firebug and I don't think the store is loading anything. I'm still looking into this.
2. My second problem: I'm trying to put the values returned in the JSON response into the text boxes in the ext.window. is this the best approach or should I consider using a form?

my editStore is loaded when the user attempts to edit a record on the main page. the reason for this is because the ID is passed based to name.jsp based on the record you've clicked the edit button for:

var editStore = new Ext.data.Store({ model: 'EditStoreModel',
proxy: {
type: 'ajax',
actionMethods :
{
read : 'GET'
},
url : 'name.jsp',
reader: {
type: 'json',
root: 'Definition'
}
},
autoLoad : false
});

the data in the name.jsp will be dependant on the id. in this case the ID passed was 123456 so the name returned was Mr T:

{ "Definition":{
"DefId":"123456",
"Name":"Mr T"
}
}


in the Ext.Window, under "items:" (this is just a small segment of my code)

items: [{
fieldLabel: 'Name',
allowBlank: false,
value: 'should i have a function here that returns the value based on the field given as input?',
name: 'name',
cls: 'name-field'
},

I'm a extjs beginner - been playing around with this for fortnight or so, so I'm not even sure if my approach to loading the data is the best. Any help at all would be appreciated.

Thanks,
Moe

m0e
8 Jan 2014, 8:14 PM
solved:

store needed a proxy:


proxy: {
type: 'ajax',
url: 'Name.jsp',
reader: {
type: 'json',
root: 'Definition'
}
},



console.log(this.getAt(0).get('Name'));

scottmartin
9 Jan 2014, 5:19 AM
If you have a form, you can use form.loadData(record) to populate all of the fields.