Reputation: 9850
There is a button, when i click that there will be a call to the Server, and i will get a JSON response.
This JSON response will contain a string similar to
{
"value": "Success",
"information": {
"firstName": "kei",
"surname": "chan"
}
}
The value
field in the JSON will be either SUCCESS or FAIL. So if it is success
, i will have to navigate to another view and display the firstName
and surname
.
I will need to pass the values firstName
and lastName
to the other view if so.
How can i pass the values of firstName
and lastName
in senchaTouch/cordova ?
Code:
the button
xtype:'button',
id:'when_button_click',
text:'Send',
ui:'confirm',
Controller class
extend: "Ext.app.Controller",
config: {
refs: {
newNoteBtn: "#when_button_click"
},
control: {
newNoteBtn: {
tap: "onNewNote"
}
}
},
onNewNote: function () {
var values = Ext.getCmp('form').getValues();
console.log("inside onNewNote function");
Ext.Ajax.request({
url: 'http://call.com/the_webservice',
params : values,
failure: function (response) {
var text = response.responseText;
console.log("fail");
}, success: function (response) {
var text = response.responseText;
console.log("success");
}
});
}
// init and launch functions omitted.
});
Upvotes: 2
Views: 2489
Reputation: 110
You can simply add additional properties into the new View object that the controller is creating. For example if the controller handler function is "pushing" a new view like so
this.getSomeView().push({
xtype : 'mylistView',
prop1 : 'my property to pass',
prop2 : record.get('comesFromTheEventHandled')
});
Then the view can access these properties in the initialize() function. For the code sample -- in the "mylistView" initialize() section you access these properties as
this.prop1 and this.prop2
Upvotes: 0
Reputation: 2331
Assuming you have a navigation view with the id 'yourNavigationViewId'
and the view you are trying to show is defined as 'Appname.view.Viewname'
, in your success handler for your ajax call, do something like this: (you can pass all the config stuff in the second argument of Ext.create
)
success: function (response) {
Ext.getCmp('yourNavigationViewId').push(Ext.create('Appname.view.Viewname', {
data: response
}));
}
Upvotes: 1