ExtJS How to implement page value delivery and acceptance ExtJS how to implement page value delivery and acceptance

Source: Internet
Author: User

ExtJS How to implement page value delivery and acceptance
ExtJS and what language do background processing does not matter, use the following method to pass the value of the past, and then the corresponding language to receive the parameters of the normal way to receive the line,
1.ajax Method Transfer value:
Ext.Ajax.request ({
URL: ' doaction.jsp method=add ',
Params:{username: ' Zhang San ', Gender: ' Male '},//parameter list
Callback:function (options,success,response) {//callback function
if (success) {
alert (response.responsetext);//Return Data
}
}
})
2. Table only son values
Define a Ext.form.FormPanel, (the name of the background receive parameter is the ID of each element of the form)
var itemform = new Ext.form.FormPanel ({...})
Then use the Itemform.getform (). Submit form:
Itemform.getform (). Submit ({
Waitmsg: ' Saving data, please wait ... ',
Waittitle: ' Hint ',
Method: ' POST ',
URL: ' dataaction.jsp method=save ',
Params:{username: ' Zhang San ', Gender: ' Man '},
Success:function (form,action) {
Do something here
},
Failure:function (form,action) {
Ext.Msg.alert (' Hint ', ' save failed. ‘);
}
})
------------------------------------------------------------the sad dividing line----------------------------------
This is a long-standing question about the use of this in JavaScript. We will not introduce its development history here, only with specific examples, to tell you what problems you may encounter, in the face of these problems when EXT is resolved. When using ext, the most common problem encountered when using the Ajax callback function, as shown in the following code.

There is now a text input box and a button in the HTML page. We want to press this button, we can use Ajax to read the background data, and then put the background response data into the text, the implementation process as shown in Listing 10-6.
Code listing 10-6 using callback functions in Ajax
function Dosuccess (response) {
Text.dom.value = Response.responsetext;
}
Ext.onready (function () {
Ext.get (' button '). On (' click ', function () {
var text = ext.get (' text ');
Ext.lib.Ajax.request (
' POST ',
' 08.txt ',
{success:dosuccess},
' param= ' + encodeuricomponent (text.dom.value)
);
});
});
In the above code, AJAX has been used Ext.get (' text ') to obtain the text, thought can be used directly behind, did not think that the callback function success will not be executed in the order you write. Of course, the local variable text is not used as you would think. In fact, if you do nothing, just use the callback function, you have to re-use Ext.get (' text ') to regain the element, otherwise the browser will report the text undefined error.
Using Ext.get (' text ') to retrieve the object is also relatively simple, in some cases it is not easy to get the object to be processed, we need to get the callback function before sending an AJAX request to manipulate the object, there are two ways to choose: scope and CreateDelegate.
L set scope for Ajax.
function Dosuccess (response) {
This.dom.value = Response.responsetext;
}
Ext.lib.Ajax.request (
' POST ',
' 08.txt ',
{Success:dosuccess,scope:text},
' param= ' + encodeuricomponent (text.dom.value)
);
Add a scope:text to the callback parameter section of Ajax and point the scope of the callback function to text, which is the function of the dosuccess function to point to the text object. Then change the dosuccess to This.dom. Value, and that's it. If you want to use an object in the callback function again, you must match the scope so that you can use this in the callback function to manipulate it.
L add createdelegate () for success.
function Dosuccess (response) {
This.dom.value = Response.responsetext;
}
Ext.lib.Ajax.request (
' POST ',
' 08.txt ',
{success:doSuccess.createDelegate (text)},
' param= ' + encodeuricomponent (text.dom.value)
);
CreateDelegate can only be called on functions, it forces the this in the function to point to the object we need, and then we can refer to the object specified in CreateDelegate () directly through this in the callback function dosuccess. It can be used as an alternative to solving this problem.
If I were to choose, I would try to choose scope because createdelegate is going to encapsulate the original function and regenerate the functions object. In a simple environment, scope is sufficient, but CreateDelegate has other functions, such as modifying the invocation parameters.

ExtJS How to implement page value delivery and acceptance ExtJS how to implement page value delivery and acceptance

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.