有一個按鈕,當我點擊它時會有一個對服務器的調用,並且我會得到一個JSON響應。將值從'Controller'傳遞給'View'類
這JSON響應將包含類似於一個字符串
的value
字段在JSON將成功或失敗。所以如果它是success
,我將不得不導航到另一個視圖並顯示firstName
和surname
。
如果需要,我需要將值firstName
和lastName
傳遞給另一個視圖。
如何在senchaTouch/cordova中傳遞firstName
和lastName
的值?
代碼:
按鈕
xtype:'button',
id:'when_button_click',
text:'Send',
ui:'confirm',
Controller類
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.
});
我的代碼'Ext.getCmp( 'myPanel')推動({ 的xtype: 'MyView的' 。 });',這是導航部分,但我如何傳遞和檢索'數據'到另一個視圖?代碼中的「響應」是什麼? –
我的代碼中的'response'來自你的例子(json響應)。請比較我的代碼中的'push'方法和您的代碼的內容。用一個簡單的javscript對象創建一個內聯視圖。在我的例子中,我使用'Ext.create'創建視圖並將配置作爲第二個參數傳遞。這是將數據放入視圖的地方。 – Michael
順便說一句:是不是像http://stackoverflow.com/questions/10471708/passing-values-back-to-the-view-from-controller-class – Michael