EXT object-oriented development practices (continued)

Source: Internet
Author: User

To perform operations on the data in the data table, the first step is to obtain the data in the data table. Article The method for creating a store in is also slightly adjusted to allow it to read data from the data table. CopyCode The Code is as follows: This. departmentstore = new Ext. Data. jsonstore ({
Proxy: New Ext. Data. httpproxy ({URL: "http: // localhost: 8080/test_ext/DB/department. php "}),
Fields: ["department_code", "department_name", "manager", "division_code"]
});

Department. php is responsible for connecting to the SQL database, obtaining data and converting it to the JSON format to prepare for ext reading.Copy codeThe Code is as follows: <? PHP
Require ('json. php ');
Require ('uai _ personal_info.php ');
$ P = new uai_personal_info ();
$ Result = $ p-> getdepartmentlist ();
$ JSON = new services_json ();
Echo $ JSON-> encode ($ result );
Another point to modify is to add and modify the onsubmitclick method of the form.
Onsubmitclick: function (){
If (this. url! = ""){
This. Form. Submit ({URL: This. url, success: This. onsubmit,
Waittitle: "save data", waitmsg: "transcation process...", scope: This });
This. fireevent ("Submit", this, this. Form. getvalues ());
}
},

The submit method must pass a series of parameters:
URL: the URL address for data processing. Here, a URL is passed in to process new operations.
Success: If the submitted data processing is successful, the processing code specified by this parameter is called back.
Waittitle: the title of the dialog box that appears when data is submitted
Waitmsg: Information in the pop-up dialog box when data is submitted
Scope: the object referred to by this in the callback function

it must be noted that a JSON string must be returned in the PHP file for data processing. If the string contains "success: True", the string is processed into or. Otherwise, the processing fails. For example, the following code copy Code is as follows: require ('json. PHP ');
require ('uai _ personal_info.php');
$ Rs =$ _ post;
$ Rs ["success"] = true; // indicates that the processing is successful
$ SQL = "insert into uai_department (department_code, department_name, Manager, division_code) values ('".
$ _ post ["department_code"]. "','". $ _ post ["department_name"]. "','". $ _ post ["manager"]. "','". $ _ post ["division_code"]. "')";
$ P = new uai_personal_info ();
$ Rs ["R"] = $ p-> insert_department ($ SQL );
$ JSON = new services_json ();
echo $ JSON-> encode ($ RS);

deletion is slightly different from addition and modification. Because deletion does not require a pop-up form to operate data, we use Ext. the copy Code code of the Ajax object is as follows: Remove: function () {
var r = This. getactiverecord ();
Ext. ajax. request ({URL: "http: // localhost: 8080/test_ext/DB/delete_dept.php", Params: {department_code: R. get ("department_code") }});
This. getstore (). remove (r); // Delete client data
},

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.