View Full Version : receive return value from view

28 Nov 2011, 9:49 PM
in one method of controller, i show another common view, there is a "ok" button on the common view, when i tap the "ok" button, return a value to caller and close the view.

onTestTap: function(){

var view = this.getCommon();

here i want to wait for the receive value from common view for following operation, how to do???

28 Nov 2011, 10:49 PM
In your common view, when you tap on the button to close, also fire a new event which passes the value you want:

//in your common view
onButtonTap: function() {
//as a rule of thumb, we generally pass the current instance as the first argument
//and whatever you want to pass as the second argument
this.fireEvent('valuechange', this, 'myvalue');

Then in your controller, you can listen to that event using control:

//in your controller
init: function() {
//this must be the xtype of your 'common view'
'commonview': {
'valuechange': 'onValueChange'

onValueChange: function(commonView, newValue) {
//do whatever you want with the new value
alert('newValue: ' + newValue);

28 Nov 2011, 11:13 PM
thanks, i know this solution.

but in the event response function, the context when show the common view is lost.

28 Nov 2011, 11:23 PM
Sorry, I don't understand the problem.