将值从“Controller”传递到“View”类

时间:2012-05-08 06:39:36

标签: cordova sencha-touch extjs sencha-touch-2

有一个按钮,当我点击时会有一个对服务器的调用,我将得到一个JSON响应。

此JSON响应将包含类似于

的字符串
{
    "value": "Success",
    "information": {
        "firstName": "kei",
        "surname": "chan"
    }
}

JSON中的value字段将为SUCCESS或FAIL。因此,如果是success,我将必须导航到另一个视图并显示firstNamesurname

如果是的话,我需要将值firstNamelastName传递给其他视图。

如何在senchaTouch / cordova中传递firstNamelastName的值?

代码:

按钮

xtype:'button',
                   id:'when_button_click',
                   text:'Send',
                   ui:'confirm',

控制器类

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.
                  });

2 个答案:

答案 0 :(得分:1)

假设您有一个标识为'yourNavigationViewId'的导航视图,而您尝试显示的视图定义为'Appname.view.Viewname',则在您的ajax调用的成功处理程序中,执行以下操作:(您可以传递Ext.create

的第二个参数中的所有配置内容
success: function (response) {
    Ext.getCmp('yourNavigationViewId').push(Ext.create('Appname.view.Viewname', {
        data: response
    }));
}

答案 1 :(得分:0)

您只需将其他属性添加到控制器正在创建的新View对象中。例如,如果控制器处理程序功能是"推动"像这样的新观点

this.getSomeView().push({   
   xtype : 'mylistView',
   prop1 : 'my property to pass',
   prop2 : record.get('comesFromTheEventHandled')
});

然后视图可以在initialize()函数中访问这些属性。 对于代码示例 - 在" mylistView" initialize()部分您将这些属性作为

进行访问
this.prop1 and this.prop2
相关问题