PDA

View Full Version : Load data into a Form from a Datastore?



steve1964
16 Sep 2010, 8:43 AM
How to load data into a Form from a datastore?
I have a datastore, a model and form, i've tried to look at the examples but no one is related to datastore.
An example would be appreciated, thanks...

elishnevsky
16 Sep 2010, 9:48 AM
What is the problem?
Retrieve a record from your store and pass it to form.load() method.
http://dev.sencha.com/deploy/touch/docs/?class=Ext.form.FormPanel&member=load
Just make sure that the form field names match the names of your model fields.

steve1964
16 Sep 2010, 10:06 AM
Thanks, but the point is that i don't know the syntax to do that, assuming my model is called Profile and the datastore ProfileStore,the datastore is loaded according then Profile Model and then?
form.load(of what?), i'm missing the point...

jay@moduscreate.com
16 Sep 2010, 10:09 AM
Having a store just to load data into a form seems wasteful to me.

elishnevsky
16 Sep 2010, 10:12 AM
Thanks, but the point is that i don't know the syntax to do that
That's what the Documentation is for. Suppose you want to load the first record from the store into the form.

var record = ProfileStore.getAt(0);
yourForm.load(record);This should do it.

steve1964
16 Sep 2010, 10:21 AM
Yes, thanks a lot, exactly what i need, i know that this can be achieved by doing an Ajax request in this form:


var profiledata = Ext.ModelMgr.create(AjaxResponse, 'profile');
this.profileForm.load(profiledata);

but i like more datastore way...

steve1964
17 Sep 2010, 9:48 AM
I solved in this way:


var profile = Ext.regModel('profile',{
fields: [
{ name: 'username', type: 'string' },
{ name: 'alias', type: 'string' },
{ name: 'sex', type: 'string' },
{ name: 'AgeRange_ageRangeId', type: 'string' }
]
});


Ext.Ajax.request({
url: 'php/profile_load.php?username=' + formL.getValues().username,
success: function(response, opts) {
var responseObj=Ext.decode(response.responseText);
if(responseObj.success){
try {
console.log(responseObj.text.alias);
} catch (e) {

}
var profiledata = Ext.ModelMgr.create(responseObj.text, 'profile');
formP.load(profiledata);
} else {
alert(responseObj.text);
}
},
failure:function(response, opts){

},
scope:this
});

torrante
13 Feb 2013, 3:44 PM
How to load a dynamic list (mysql/php) into combobox???:((