发布于 2016-12-14 03:56:19 | 148 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

ExtJS Javascript库

ExtJS是一种主要用于创建前端用户界面,是一个基本与后台技术无关的前端ajax框架。


我的上一篇文章《Ext面向对象开发实践》中简述了如何编写一个面向对象的数据维护小程序,但这一些都是基于一个客户端数据,即用户一旦刷新页面,所有的操作都将丢失,现在我们就接着上一篇文章来继续讲一下如何对数据表进行增、删、改、查操作。
要实现对数据表中的数据进行操作,第一步就是要取得数据表中的数据,我们把上篇文章中的创建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); //删除客户端数据 
},


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务