PDA

View Full Version : updating data on button click



KrullWarKing
14 Jun 2010, 8:08 AM
I have a an extension to an xml datastore:

MyStore = Ext.extend(Ext.data.XmlStore, {
constructor: function(cfg) {
cfg = cfg || {};
MyStore.superclass.constructor.call(this, Ext.apply({
storeId: 'MyStore',
url: 'http://maps.google.com/maps/api/geocode/xml?address=37043&sensor=false',
record: 'address_component',
autoLoad: true,
autoDestroy: true,
fields: [
{
name: 'long_name'
},
{
name: 'short_name'
},
{
name: 'type'
}
]
}, cfg));
}
});
new MyStore();

Later in my app I want the user to be able to change the zip code in the call to google api

{
xtype: 'panel',
height: 87,
layout: 'auto',
items: [
{
"xtype": "textfield",
"id" : "zipgetter",
"fieldLabel": "Zip Code:",
"width": 200
},
{
"xtype": "button",
"text": "Get lat/lng",
"width": 200,
handler: function(){
var v = Ext.get('zipgetter').getValue();
//var lastOptions = MyStore.lastOptions;
//Ext.MessageBox.alert(MyStore);
//Ext.apply(lastOptions.params, {
// url:'http://maps.google.com/maps/api/geocode/xml?address='+v+'&sensor=false' (http://www.extjs.com/forum/'http://maps.google.com/maps/api/geocode/xml?address='+v+'&sensor=false')
//});
//MyStore.reload(lastOptions);
MyStore.reload({params:{url:'http://maps.google.com/maps/api/geocode/xml?address='+v+'&sensor=false'}});
}

}
]
}

any help would be appreciated.

CrazyEnigma
14 Jun 2010, 7:16 PM
Notice how hard it is to read this post. Please apply some CODE tags, and read this first (http://www.extjs.com/forum/showthread.php?66423-****-READ-ME-FIRST-****-Guidelines-FAQs-Resources-etc). You can edit your original post to see if you would get a better response.

Luckily it's pretty straightforward code.

It would be preferable if you used:


url: "http://maps.google.com/maps/api/geocode/xml"
baseParams: {
sensor: false
address: 37043
}


Later, you can use:


MyStore.load({
params: {address: v}
}


In case "v" ever needed to be urlEncoded, you would have to do this, however in the above code, there is no need.

KrullWarKing
15 Jun 2010, 5:26 AM
Also will do on the code marking.:D