php生成extjs下拉树json数据格式
菜单项curd以及extjs下拉树json数据构造
<?php
// +----------------------------------------------------------------------// | thinkphp+extjs +jquery CMS管理系统// +----------------------------------------------------------------------// | Copyright (c) 2010 http://blog.aigouw.net All rights reserved.// +----------------------------------------------------------------------// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )// +----------------------------------------------------------------------// | Author: 殷志朋 <601046124@qq.com> 7391390// +----------------------------------------------------------------------// | Q&A: 群 7391390// +-----class MenuItemAction extends Action {
/** * 取出所有菜单项 */ function ListAll() {
$keyword = $_POST['searchstring']; $limit = $_POST['limit']; $start = $_POST['start']; $limits = $start . "," . $limit; if (!empty($keyword)) { $where['name'] = array('like', '%' . $keyword . '%'); $_SESSION['keyword'] = $where; } else { if (empty($keyword)) { unset($_SESSION['keyword']); } else if (!empty($_SESSION['keyword'])) { $where = $_SESSION['keyword']; } } $menuitem = new MenuItemModel(); $keyword = $_POST['keyword']; $ftype = $_POST['ftype']; if (!empty($keyword) && !empty($ftype)) { $where[$ftype] = array('like', '%' . $keyword . '%'); $_SESSION['keyword'] = $where; } else { if (empty($keyword) && !empty($ftype)) { unset($_SESSION['keyword']); } else if (!empty($_SESSION['keyword'])) { $where = $_SESSION['keyword']; } } if (!empty($_REQUEST['id'])) { $_SESSION['menuid'] = $_REQUEST['id']; $where['menuid'] = $_SESSION['menuid']; } elseif ($_SESSION['menuid']) { $where['menuid'] = $_SESSION['menuid']; } else { echo('请选择菜单'); }
$count = $menuitem->where($where)->count();
$list = $menuitem->field("id,name,pid,type,componentid,`order`,published,access,concat(path,'-',id) as bpath")-> order("bpath,id")->limit($limits)->where($where)->select(); $role = new Model('Role'); $rlist = $role->getField('id,name');
foreach ($list as $key => $value) { if ($list[$key]['access'] != 0) { $list[$key]['access'] = $rlist[$list[$key]['access']]; } $list[$key]['signnum'] = count(explode('-', $value['bpath'])) - 1; $list[$key]['marginnum'] = (count(explode('-', $value['bpath'])) - 1) * 20; }
if ($list) {
$result = json_encode($list); echo '{"totalCount":' . $count . ',"data":' . $result . '}'; } else { echo '{"totalCount":' . $count . ',"data":[{"id":"0","name":"<font color=red><b>暂无记录</b></font>"}]}'; } }
/** * 构造路径 */ function GetPath() { $menu = new MenuItemModel(); $pid = $_POST['pid']; $mi = $menu->field('id,path')->getById($pid); $path = $pid != 0 ? $mi['path'] . '-' . $mi['id'] : 0; return $path; }
/** * 添加 */ function Add() { $menu = new MenuItemModel(); switch ($_POST['fenlei']) { case '1':$_POST['fenlei'] = 'Article'; case '2':$_POST['fenlei'] = 'Section'; case '3':$_POST['fenlei'] = 'Category'; } $data['link'] = 'index.php/' . $_POST['fenlei'] . '/view/id/' . $_POST['ctype']; $data['access'] = $_POST['access']; $data['published'] = $_POST['published'];
$data['browserNav'] = $_POST['nav']; $data['name'] = $_POST['name']; $data['type'] = $_POST['fenlei']; $data['menuid'] = $_POST['menuid']; $data['path'] = $this->GetPath(); $data['pid'] = $_POST['pid'];
if (false !== $menu->data($data)->Add()) { echo '{"success":true}'; } else { echo '{"success":false}'; } }
/** * 保存 */ function Save() { $menu = new MenuItemModel(); switch ($_POST['fenlei']) { case '1':$_POST['fenlei'] = 'Article'; case '2':$_POST['fenlei'] = 'Section'; case '3':$_POST['fenlei'] = 'Category'; } $data['link'] = 'index.php/' . $_POST['fenlei'] . '/view/id/' . $_POST['ctype']; $data['access'] = $_POST['access']; $data['published'] = $_POST['published'];
$data['browserNav'] = $_POST['nav']; $data['name'] = $_POST['name']; $data['type'] = $_POST['fenlei']; $data['menuid'] = $_POST['pid']; $data['path'] = $this->getPath(); $data['id'] = $_POST['id'];
if (false !== $menu->data($data)->Save()) { echo '{"success":true}'; } else { echo '{"success":false}'; } }
/** * 移除 */ function Remove() { $did = $_POST['deleteIds']; if (!empty($did)) { $user = new MenuItemModel();
if (false !== $user->where('id in(' . $did . ')')->delete()) {
echo "{'success':true}"; } else {
echo "{'success':true}"; } } else { echo "{'success':true}"; } }
/** * 构造路径 */ function ParentMenu() { $menuitem = new MenuItemModel(); $result = $menuitem->field("id,name,pid,type,componentid,`order`,published,access,concat(path,'-',id) as bpath")-> order("bpath,id")->where('pid=' . $_SESSION['menuid'])->select(); $json = array(); $ids = array(); foreach ($result as $val) { if (in_array($ids, $val['id'])) { return; } ; array_puah($val['id'], $ids); $json['id'] = $val["id"]; $json['text'] = $val["name"]; $json['leaf'] = 'true'; foreach ($resultc as $cval) { if ($cval['pid'] = $val['id']) { $json['children']['id'] = $cval['id']; $json['children']['text'] = $cval['name']; $json['children']['leaf'] = 'false'; } } } if ($result) { $result = json_encode($result); echo $result; } else { echo "{'success':false}"; } }
/** * 构造extjs下拉树内层数据 */ function InsideTree($list) { $str = ''; foreach ($list as $key => $value) { //遍历列表 if ($str != '') $str .= ','; $in_str = ''; foreach ($value as $n => &$v) { //遍历数组 if ($in_str != '') $in_str .= ','; if ($n == 'leaf') { $in_str .= $n . ":" . $v; } else { if ($n == 'children' && is_array($v)) { $v = $this->InsideTree($v); $in_str .= $n . ":" . $v; } else { $in_str .= $n . ":'" . $v . "'"; } } } $str .= '{' . $in_str . '}'; } return $str = '[' . $str . ']'; }
/** * 完成extjs下拉树内层数据构造 */ function Tree() { $menuitem = new MenuItemModel(); $result = $menuitem->field("id,name as text,pid,type")->select(); $tree = new TreeAction(); $tree->input_arr = $result;
$data = $tree->GetTreeData(0); echo "[{id:'0',text:'顶层菜单',children:" . $this->InsideTree($data) . "}]"; }
function Art() { $limit = $_POST['limit']; $start = $_POST['start']; $limits = $start . "," . $limit; $role = new ArticleViewModel(); $where['Article.published'] = array('gt', 0); $count = $role->where($where)->count(); $result = $role->order('id')->where($where)->limit($limits)->select(); if ($result) {
$result = json_encode($result); echo '{"totalCount":' . $count . ',"root":' . $result . '}'; } else { echo '{"totalCount":' . $count . ',"root":[{"id":"0","atitle":"<font color=red><b>暂无记录</b></font>"}]}'; } }
function Car() { $limit = $_POST['limit']; $start = $_POST['start']; $limits = $start . "," . $limit; $role = new CategoryViewModel(); $where['Category.published'] = array('gt', 0); $count = $role->where($where)->count(); $result = $role->order('id')->where($where)->limit($limits)->select(); foreach ($result as & $val) { $val['atitle'] = $val['ctitle']; } if ($result) {
$result = json_encode($result); echo '{"totalCount":' . $count . ',"root":' . $result . '}'; } else { echo '{"totalCount":' . $count . ',"root":[{"id":"0","atitle":"<font color=red><b>暂无记录</b></font>"}]}'; } }
function Sec() { $limit = $_POST['limit']; $start = $_POST['start']; $limits = $start . "," . $limit; $role = new SectionModel(); $where['published'] = array('gt', 0); $count = $role->where($where)->count(); $result = $role->order('id')->where($where)->limit($limits)->select(); foreach ($result as & $val) { $val['atitle'] = $val['title']; } if ($result) {
$result = json_encode($result); echo '{"totalCount":' . $count . ',"root":' . $result . '}'; } else { echo '{"totalCount":' . $count . ',"root":[{"id":"0","atitle":"<font color=red><b>暂无记录</b></font>"}]}'; } }
}
?>
<?php// +----------------------------------------------------------------------// | thinkphp+extjs +jquery CMS管理系统// +----------------------------------------------------------------------// | Copyright (c) 2010 http://blog.aigouw.net All rights reserved.// +----------------------------------------------------------------------// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )// +----------------------------------------------------------------------// | Author: 殷志朋 <601046124@qq.com> 7391390// +----------------------------------------------------------------------// | Q&A:群 7391390// +----------------------------------------------------------------------//class TreeAction {
/** * 生成数所需要的二维数组 */ public $input_arr;
/** * 数组父键值 */ public $parent_tag = 'pid';
public function __construct($arr = array()) { $this->input_arr = $arr; return is_array($this->input_arr); }
/** * 递归取树形纯数组 * @param int $start_id 从哪个id开始遍历,0为根节点 * @return array 排序好的数组 */ public function GetTreeData($start_id = 0, $leaf = false) { $tree_arr = array(); $child = $this->GetChild($start_id, $leaf);
if (is_array($child) && $child) { foreach ($child as &$child_value) { $tree_arr[$child_value['id']] = $child_value; $data = $this->GetChild($child_value['id']); if (is_array($data) && count($data) >= 1) { $leaf = 'false'; } else { $leaf = 'true'; }
$tree_arr[$child_value['id']]['leaf'] = $leaf; $tree_arr[$child_value['id']]['children'] = $this->GetTreeData($child_value['id']); } } return $tree_arr; }
/** * 获取子元素 * @param string $my_id 其id * @return array $data 子元素数组 */ private function GetChild($my_id, $leaf) { $data = array(); foreach ($this->input_arr as $key => $value) { if ($value[$this->parent_tag] == $my_id) {
$data[$key] = $value; } }
return $data; }
}
?>
php生成extjs下拉树json数据格式相关推荐
- ajax使用json下拉框,ajax请求后台得到json数据后动态生成树形下拉框的方法
如下所示: $(function(){ $.ajax({ url:"departmentAction_getAllDep.action", type:"post" ...
- extjs多选下拉树
extjs多选下拉树 发表于 2012 年 7 月 15 日 由 q601046124 extjs多选下拉树 extjs多选下拉树 详情 见 http://blog.aigouw.net ...
- extjs tree下拉列表_使用ztree来代替Extjs的下拉树
[Struts2+Spring2.5+Hibernate3(JPA)+ExtJS3基本后台 将ExtJS替换为3..2版本后发现下拉数有些异常:之前展开下来树的下级节点时,下拉菜单不会关掉.但是在3. ...
- 在ExtJS的ComboBox组件中实现下拉树效果
2019独角兽企业重金招聘Python工程师标准>>> 看了很多关于EXT下拉树的实现, 发现很多例子都是对EXT原有的类进行扩展, 而且都发现用起来很费劲,在这里,本人实现的EXT ...
- extjs2.0 ie8 下拉树_extjs2下拉树选项框comboxWithTree(支持异步加载子节点)
extjs版本:2.2 简介:支持单选.异步加载子节点(当然一下子拼接好全部节点的json也是绝对没问题的),要支持多选则需要自行设置,(已测试通过)浏览器兼容ie8.谷歌.FF. 资料参考:搜索一下 ...
- xm-select下拉框,下拉树
使用案例 先上图 layui中使用xm-select下拉选择树 1.引入js <script src="../static/res/bootstrap/js/jquery-3.4.1. ...
- zTree开发下拉树
最近,因为工作需要一个树形下拉框的组件,经过查资料一般有两种的实现方法.其一,就是使用zTree实现:其二,就是使用easyUI实现.因为公司的前端不是使用easyUI设计的,故这里我选择了zTree ...
- dtree渲染下拉树,layui集成dtree,dtree渲染下拉框
文档位置 dtree官方文档地址链接 渲染下拉树js dTreeUtil.js /**** @param id 要渲染的dom* @param data 数据* @param none 无数据时显示 ...
- asp.net DataGridTree表格树控件 下拉树 DropTree c# .net
1.下拉树 DropTree c# .net 下拉树实现原理 输出json到客户端 客户端实现动态加载 中间不会和服务端交互 数据量支持上 经测试 几千 还是很快的 本下拉树控件是用c#+js树实现 ...
最新文章
- 星期和工作日计算,你会了吗?
- XenStore: 使用,结构和原理
- malloc与calloc的区别
- 【Python】青少年蓝桥杯_每日一题_1.03_输出字符串
- DL之Keras: Keras深度学习框架的注意事项(默认下载存放路径等)、使用方法之详细攻略
- 备份自己常用的VS2010设置
- 苹果计算机怎么添加在快捷方式,如何在 iPhone 主屏幕上添加文件快捷方式?
- oracle11.2.0.4使用impdp导入时报错:ORA-39083 ORA-00439
- 腾达无线加密与Win7
- 文件二维码制作生成网站
- 国际产品经理资格认证NPDP 2017
- vnr懒人版教程_【visual novel reader最新版】visual novel reader翻译懒人整合版下载 百度云资源 最新版-七喜软件园...
- 学计算机去一线城市,这5个“新一线”城市在线抢人,选择去这上大学非常有前景!...
- 【Verilog基础】卡诺图化简要点总结
- 做最好的自己——摘自李镇西的《做最好的老师》
- golang快速入门[3]-go语言helloworld
- 设计模式六大原则的理解与归纳
- 什么是大数据?以及大数据的5V特性
- Axon Framework架构概述
- 使用final来修饰方法
热门文章
- Qt5.9生成dll详细步骤
- Swift5关于根据一个frame得到最大X值和最大Y值
- git:The authenticity of host 'github.com (13.250.177.223)' can't be established.
- Keras和TensorFlow的关系和区别
- linux cacti 搭建,Cacti搭建部署
- ensp静态路由的配置及分析
- 安装Mediamanager 后Messenger后无法登录
- linux安全运维(一)
- 堆内存破坏检测实战--附完整调试过程
- RSS 没有死亡 而是无所不在