PDA

View Full Version : Load store on form submit.



maps_tecnologia
9 Jan 2012, 1:00 PM
Hello,

When I submit my form, I get a json response back that I want to load on my store.



buttons: [{
text: 'Exibir',
handler: function(){
var form = form || this.up('form').getForm();
form.submit(
{
method: 'GET',
url:'a/b/getSMT',
HOW CAN I LOAD MY STORE HERE?
}
);
}
}]

Store:

Ext.define('MyApp.store.bla', { extend: 'Ext.data.JsonStore',
model: 'MyApp.model.bla'
});

Model:

Ext.define('MyApp.model.bla', { extend: 'Ext.data.Model',
fields: [
'a',
'b',
'c',
'd'
]
});

mitchellsimoens
9 Jan 2012, 1:13 PM
use the success config of the submit function. You will have access to the response in the 2nd argument I believe.

maps_tecnologia
10 Jan 2012, 5:02 AM
form.submit(
{
method: 'GET',
url:'a/b/getSMT',
success: function (req, res) {
alert("bla");
console.log('yadda');
}
}
);


This should work right? It doesns't...
Does the GET verb get a success response like the POST?

I know it's a form and it's supposed to POST, but I am actually GETting something, not modifying.

Am I missing something?

mitchellsimoens
10 Jan 2012, 5:05 AM
Are you returning JSON?


{ "success" : true }

maps_tecnologia
10 Jan 2012, 5:27 AM
The failure callback is working, so I guess it's a GET issue.

Btw I triyed loading my response to my store but my grid shows nothing.


failure: function (response, request) {
myStore.loadData(response);
}

maps_tecnologia
10 Jan 2012, 7:37 AM
Are you returning JSON?


{ "success" : true }

I did that and now the success callback works, but I am not able to load that JSON to my store.


success: function (response, request) {
pontosStore.loadData(response);
}


Am I missing something?

mitchellsimoens
10 Jan 2012, 7:42 AM
You have the arguments wrong in the success callback. The first is the form and the second is the action. Take a look at the action argument.

maps_tecnologia
10 Jan 2012, 8:05 AM
pontosStore.loadData(action.response.responseText);


I guess it loads the data, but somehow my browser freezes and I can see in my console.log(pontoStore) that the data array has more then 35000 items, when it should be like 20. Its like its looping.

maps_tecnologia
10 Jan 2012, 12:23 PM
Got it:


form.submit(
{
method: 'GET',
url:'a/b/getSMT',
headers: { 'Content-Type': 'application/json' },
success: function (form, action) {
var jsonResp = Ext.decode(action.response.responseText, true).root;
pontosStore.loadData(jsonResp);
}
}
);