欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Ext面向?qū)ο箝_(kāi)發(fā)實(shí)踐(續(xù))

 更新時(shí)間:2008年11月18日 00:41:32   作者:  
我的上一篇文章《Ext面向?qū)ο箝_(kāi)發(fā)實(shí)踐》中簡(jiǎn)述了如何編寫(xiě)一個(gè)面向?qū)ο蟮臄?shù)據(jù)維護(hù)小程序,但這一些都是基于一個(gè)客戶端數(shù)據(jù),即用戶一旦刷新頁(yè)面,所有的操作都將丟失,現(xiàn)在我們就接著上一篇文章來(lái)繼續(xù)講一下如何對(duì)數(shù)據(jù)表進(jìn)行增、刪、改、查操作。
要實(shí)現(xiàn)對(duì)數(shù)據(jù)表中的數(shù)據(jù)進(jìn)行操作,第一步就是要取得數(shù)據(jù)表中的數(shù)據(jù),我們把上篇文章中的創(chuàng)建Store的方法也略作調(diào)整,讓其從數(shù)據(jù)表中讀取數(shù)據(jù)。
復(fù)制代碼 代碼如下:

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,負(fù)責(zé)連接SQL數(shù)據(jù)庫(kù),取得數(shù)據(jù)并將其轉(zhuǎn)換為JSON格式,為Ext的讀取作準(zhǔn)備。
復(fù)制代碼 代碼如下:

<?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);
還有一點(diǎn)要修改的就是新增和修改窗體的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方法需要傳遞一系列參數(shù):
url:數(shù)據(jù)處理的URL地址,這里傳入的是一個(gè)負(fù)責(zé)處理新增操作的URL
success:如果提交數(shù)據(jù)處理成功,則會(huì)回調(diào)這個(gè)參數(shù)指定的處理代碼
waitTitle:數(shù)據(jù)提交時(shí)彈出對(duì)話框的標(biāo)題
waitMsg:數(shù)據(jù)提交時(shí)彈出對(duì)話框的信息內(nèi)容
scope:回調(diào)函數(shù)中的this所指對(duì)象

這里需要說(shuō)明的是處理數(shù)據(jù)的PHP文件中,必須返回一個(gè)JSON字串,如果包含"success: true",則表示處理成或,否則認(rèn)為處理失敗。例如下面的代碼
復(fù)制代碼 代碼如下:

<?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);


刪除的處理則與新增、修改略有不同,因?yàn)閯h除不需要彈出窗體對(duì)數(shù)據(jù)進(jìn)行操作,所以我們改用Ext.Ajax對(duì)象
復(fù)制代碼 代碼如下:

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); //刪除客戶端數(shù)據(jù)
},

相關(guān)文章

最新評(píng)論