Home >Web Front-end >JS Tutorial >Ext object-oriented development practice (continued)_YUI.Ext related

Ext object-oriented development practice (continued)_YUI.Ext related

WBOY
WBOYOriginal
2016-05-16 18:58:38925browse

To operate the data in the data table, the first step is to obtain the data in the data table. We also slightly adjusted the method of creating the Store in the previous article to read data from the data table.

Copy code 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, responsible for connecting to the SQL database, obtaining data and converting it into JSON format to prepare for reading Ext.
Copy code The code is as follows:

require('JSON. php');
require('uai_Personal_Info.php');
$p = new uai_Personal_Info();
$result = $p->getDepartmentList();
$json = new Services_JSON ();
echo $json->encode($result);
One more thing 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 needs to pass a series of parameters:
url: The URL address of data processing. What is passed here is a URL responsible for processing new operations.
success: If the submitted data is processed successfully, the parameter specified by this parameter will be called back. Processing code
waitTitle: the title of the dialog box that pops up when data is submitted
waitMsg: the information content of the dialog box that pops up when data is submitted
scope: the object pointed to by this in the callback function

Required here What is explained is that in the PHP file that processes data, a JSON string must be returned. If it contains "success: true", it means that the processing is or, otherwise it is considered that the processing failed. For example, the following code
Copy the code The code is as follows:

require ('JSON.php');
require('uai_Personal_Info.php');
$rs = $_POST;
$rs["success"] = true; //Indicates successful processing
$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);


The processing of deletion is slightly different from adding and modifying, because deletion does not require a pop-up form to operate on the data, so we use the Ext.Ajax object instead
Copy code The code 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
},
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn