Ext物件導向開發實踐(續)

來源:互聯網
上載者:User

要實現對資料表中的資料進行操作,第一步就是要取得資料表中的資料,我們把上篇文章中的建立Store的方法也略作調整,讓其從資料表中讀取資料。 複製代碼 代碼如下: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,負責串連SQL資料庫,取得資料並將其轉換為JSON格式,為Ext的讀取作準備。 複製代碼 代碼如下:<?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);
還有一點要修改的就是新增和修改表單的onSubmitClick方法
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());
}
},

Submit方法需要傳遞一系列參數:
url:資料處理的URL地址,這裡傳入的是一個負責處理新增操作的URL
success:如果提交資料處理成功,則會回調這個參數指定的處理代碼
waitTitle:資料提交時彈出對話方塊的標題
waitMsg:資料提交時彈出對話方塊的資訊內容
scope:回呼函數中的this所指對象

這裡需要說明的是處理資料的PHP檔案中,必須返回一個JSON字串,如果包含"success: true",則表示處理成或,否則認為處理失敗。例如下面的代碼 複製代碼 代碼如下:<?php
require('JSON.php');
require('uai_Personal_Info.php');
$rs = $_POST;
$rs["success"] = true; //表示處理成功
$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);

刪除的處理則與新增、修改略有不同,因為刪除不需要彈出表單對資料進行操作,所以我們改用Ext.Ajax對象 複製代碼 代碼如下: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); //刪除用戶端資料
},

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.