将值从“Controller”类传递回“View” [英] Passing values back to the 'View' from 'Controller' class
问题描述
{value:SUCCESS}
现在,我需要将这个JSON字符串发送回该视图,视图将根据JSON响应提醒用户。如果JSON返回SUCCESS,则会显示Success警报,如果JSON返回FAIL,则会显示Fail警报。
1)在我的代码中,我只能显示来自VIEW的JSON响应,但是如何将它发送到COntroller? ( var text = response.responseText;
显示JSON响应)
2。)我如何分开字符串,只能从JSON响应中获取SUCCESS或FAIL字符串?
按钮实现,从视图类
xtype:'button',
id:'when_button_click',
文本:'发送',
ui:'确认',
COntroller CLass
Ext.define('myapp.controller.testcont',{
Ext.app.Controller
config:{
refs:{
newNoteBtn:#when_button_click
},
control:{
newNoteBtn :{
点击: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);
}
});
}
//初始化和启动功能省略。
});
1)我的代码,我只能显示来自VIEW的JSON响应,但是如何将它发送到COntroller?
将值从控制器
中的视图
中传递
我没有看到任何有效的理由这样做。
您可以在控制器本身的成功中显示
Ext.Msg.alert
/ code>和失败
这样的Web服务,
.....
.....
url:'http://call.com/the_webservice',
params:values,
failure :function(response){
var text = response.responseText;
Ext.Msg.alert('Error','执行Web Service时出错');
},
success:function(response){
var text = response.responseText;
Ext.Msg.alert('Success','Web Service code successfully execution');
},
.....
.....
2)如何从视图中分离字符串,并从JSON响应中获取
SUCCESS或FAIL字符串?
编辑:
做这样的事情..
var result = Ext.decode(response.responseText);
// result.value = SUCCESS或FAIL
Ext.Msg.alert('Message',result.value);
In my VIew, i have added a button and when i click on it, the Controller class gets called. The value's in the View (textfield values) , will be sent over the URL from the web service. Then the server will return a JSON string shown below;
{"value":"SUCCESS"}
Now, i need to sent this JSON string back to the view, and the view will alert the user depending on the JSON response. If the JSON returned SUCCESS, then a Success alert will get displayed and if the JSON returned FAIL, then a Fail alert will be displayed.
1.) In my code, i can only display the JSON response from the VIEW, but how can i send it to the COntroller ? (var text = response.responseText;
displays the JSON response)
2.) How could i, separate the string from the view, and only get the SUCCESS or FAIL string from the JSON response ?
Button Implementation, From the View Class
xtype:'button',
id:'when_button_click',
text:'Send',
ui:'confirm',
The COntroller CLass
Ext.define('myapp.controller.testcont', {
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.
});
1.) In my code, i can only display the JSON response from the VIEW, but how can i send it to the COntroller ?
Why you want to pass the values back to the view
from the controller
?
I don't see any valid reason to do so.
You can show the Ext.Msg.alert
in the controller itself on success
and failure
of Web Service like this,
.....
.....
url: 'http://call.com/the_webservice',
params : values,
failure: function (response) {
var text = response.responseText;
Ext.Msg.alert('Error','Error while executing Web Service');
},
success: function (response) {
var text = response.responseText;
Ext.Msg.alert('Success','Web Service code successfully executed');
},
.....
.....
2) How could i, separate the string from the view, and only get the SUCCESS or FAIL string from the JSON response ?
EDIT:
Do something like this ..
var result = Ext.decode(response.responseText);
// result.value = SUCCESS or FAIL
Ext.Msg.alert('Message',result.value);
这篇关于将值从“Controller”类传递回“View”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!