起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4371|回复: 9

[结贴] 自定义action实现树状关系

[复制链接]

37

主题

132

帖子

422

积分

中级会员

Rank: 3Rank: 3

积分
422
QQ
发表于 2017-8-3 11:13:34 | 显示全部楼层 |阅读模式
版本: 其它(帖子中说明) 小版本号:
数据库: MySQL 服务器操作系统: Windows 应用服务器: Tomcat
客户端操作系统: Windows 8 浏览器: Chrome
关于这个链接的案例,http://docs.wex5.com/comps-tree/ 最后一个案例,自定义action实现树状关系,捋不清关系,做不出来。
第一:概念定义 fLeaves Integer类型 语句里
                 case 1:
            sql = "select null as fParentID,1 as fLevel,false as fIsLeaves,fID,fName from "
            + TABLE_PROVINCE+" GROUP BY fID limit "+offset+","+limit;
            sqlWhere = "";
            showTable = TABLE_PROVINCE;
            break;
        case 2:
            sql = "select fProvinceID as fParentID,2 as fLevel,false as fIsLeaves,"
            +"concat_ws('-','"+parent+"',CONVERT(fID,char)) as fID,fName from "
            + TABLE_CITY+" where fProvinceID = "+parent+" GROUP BY fID limit "+offset+","+limit;
            sqlWhere = "where fProvinceID = "+parent;
            showTable = TABLE_CITY;
            break;
        case 3:
            sql = "select fCityID as fParentID,3 as fLevel,true as fIsLeaves,"
            + "concat_ws('-','"+parent+"',CONVERT(fID,char)) as fID,fName from "
            + TABLE_COUNTY+" where fCityID = "+parent+" GROUP BY fID limit "+offset+","+limit;
            sqlWhere = "where fCityID = "+parent;
            showTable = TABLE_COUNTY;
            break;
        }
     为什么语句里要给true 和 false,跑的时候错误
Caused by: com.justep.exception.KSQLException: 编码: JUSTEP154046;
  提示: KSQL语法错误, _name as fName,^^true as fLeaves中未找到需要的元素, 位置66期望是以下元素之一:STRING, NUMBER, ONE_RELATION, IDENTIFER, VARIABLE
第二:直接手写语句,query里测试有数据,跑起来报错,第一级目录都没找到了,后台数据都传不过去更别提调试前台了
        case 1:            sql = "select F_product_info as fID,F_product_info.product_name as fName,1 as fLeaves,1 as Level ,null as fParentID from F_product_info F_product_info";            sqlWhere = "F_product_info.status = 1";            showTable = TABLE_PRODUCT;
执行sql: select F_product_info as fID,F_product_info.product_name as fName,1 as fLeaves,1 as Level ,null as fParentID from F_product_info F_product_info, binds: []出错
编码:JUSTEP150039
      Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'F_product_info' in 'field list'
综上,案例是15年的,是不是不适用了?
      卡了近一个星期了,心情有点燥。指点一下!!!谢谢。  BeX5 3.7

概念定义

概念定义

语句测试

语句测试

91

主题

13万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
36187
发表于 2017-8-3 11:46:35 | 显示全部楼层
你的概念本来就是树形的,为什么要自定义action实现?

具体需求要做什么?
远程的联系方法QQ1392416607,添加好友时,需在备注里注明其论坛名字及ID,公司等信息
发远程时同时也发一下帖子地址,方便了解要解决的问题  WeX5教程  WeX5下载



如按照该方法解决,请及时跟帖,便于版主结贴
回复 支持 反对

使用道具 举报

37

主题

132

帖子

422

积分

中级会员

Rank: 3Rank: 3

积分
422
QQ
 楼主| 发表于 2017-8-3 12:07:57 | 显示全部楼层
jishuang 发表于 2017-8-3 11:46
你的概念本来就是树形的,为什么要自定义action实现?

具体需求要做什么? ...

http://bbs.wex5.com/forum.php?mod=viewthread&tid=177919

数据不是树形,来自4张表

<concept name="F_product_info" default-value-expr="nextSeq('F_product_info')"><has-relation relation="product_name" size="128"><label language="zh_CN">产品名字</label>
</has-relation>
<has-relation relation="product_type"><label language="zh_CN">类型:1硬件2软件</label>
</has-relation>
<has-relation relation="remark" size="1024"><label language="zh_CN">备注</label>
</has-relation>
<has-relation relation="create_id" required="true"><label language="zh_CN">创建人</label>
</has-relation>
<has-relation relation="modify_id" required="true"><label language="zh_CN">修改人</label>
</has-relation>
<has-relation relation="gmt_create"><label language="zh_CN">创建时间</label>
</has-relation>
<has-relation relation="gmt_modify"><label language="zh_CN">修改时间</label>
</has-relation>
<has-relation relation="status"><label language="zh_CN">状态</label>
</has-relation>
<label language="zh_CN">产品实体表</label>
</concept>
<concept name="F_product_publish_info" default-value-expr="nextSeq('F_product_publish_info')"><has-relation relation="device_id"><label language="zh_CN">设备ID</label>
</has-relation>
<has-relation relation="type_id"><label language="zh_CN">产品型号ID</label>
</has-relation>
<has-relation relation="create_id" required="true"><label language="zh_CN">创建人</label>
</has-relation>
<has-relation relation="modify_id" required="true"><label language="zh_CN">修改人</label>
</has-relation>
<has-relation relation="gmt_create"><label language="zh_CN">创建时间</label>
</has-relation>
<has-relation relation="gmt_modify"><label language="zh_CN">修改时间</label>
</has-relation>
<has-relation relation="status"><label language="zh_CN">状态</label>
</has-relation>
<label language="zh_CN">硬件及发布产品关联表</label>
</concept>

<relation name="gmt_create" data-type="DateTime"><label language="zh_CN">创建时间</label>
</relation>
<relation name="device_name" data-type="String"><label language="zh_CN">设备名字</label>
</relation>
<relation name="product_type" data-type="Integer"><label language="zh_CN">类型:1硬件2软件</label>
</relation>
<relation name="create_id" data-type="String"><label language="zh_CN">创建人</label>
</relation>
<relation name="device_id" data-type="Integer"><label language="zh_CN">设备ID</label>
</relation>
<relation name="type_id" data-type="Integer"><label language="zh_CN">产品型号ID</label>
</relation>
<relation name="modify_id" data-type="String"><label language="zh_CN">修改人</label>
</relation>
<relation name="product_id" data-type="Integer"><label language="zh_CN">产品ID</label>
</relation>
<relation name="gmt_modify" data-type="DateTime"><label language="zh_CN">修改时间</label>
</relation>
<relation name="remark" data-type="String"><label language="zh_CN">备注</label>
</relation>
<relation name="product_name" data-type="String"><label language="zh_CN">产品型号名称</label>
</relation>
<relation name="status" data-type="Integer"><label language="zh_CN">状态 1正常 2 删除</label>
</relation>
<concept name="F_product_type_info" default-value-expr="nextSeq('F_product_type_info')"><has-relation relation="product_id"></has-relation>
<has-relation relation="type_name" size="128"><label language="zh_CN">产品型号名称</label>
</has-relation>
<has-relation relation="product_name"><label language="zh_CN">产品名称</label>
</has-relation><has-relation relation="create_id" required="true"></has-relation>
<has-relation relation="modify_id" required="true"></has-relation>
<has-relation relation="gmt_create"></has-relation>
<has-relation relation="gmt_modify"></has-relation>
<has-relation relation="status"></has-relation>
<label language="zh_CN">产品发布表</label>


<has-relation relation="gl_type_id" data-type="Integer"></has-relation>
</concept>
<relation name="type_name" data-type="String"><label language="zh_CN">产品型号名称</label>
</relation>

<concept name="F_device_info" default-value-expr="nextSeq('F_device_info')"><has-relation relation="device_name" size="16"></has-relation>
<has-relation relation="remark" size="1024"></has-relation>
<has-relation relation="create_id" required="true"></has-relation>
<has-relation relation="modify_id" required="true"></has-relation>
<has-relation relation="gmt_create"></has-relation>
<has-relation relation="gmt_modify"></has-relation>
<has-relation relation="status"></has-relation>
<label language="zh_CN">硬件实体表</label>
</concept>
<relation name="gl_type_id" data-type="Integer"><label language="zh_CN">关联表内存的发布表id</label>
</relation>
回复 支持 反对

使用道具 举报

91

主题

13万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
36187
发表于 2017-8-3 14:13:04 | 显示全部楼层
那就需要自己参考你发的链接中的案例
自己要知道根据那个字段的值去过滤获取表中的数据做子数据
远程的联系方法QQ1392416607,添加好友时,需在备注里注明其论坛名字及ID,公司等信息
发远程时同时也发一下帖子地址,方便了解要解决的问题  WeX5教程  WeX5下载



如按照该方法解决,请及时跟帖,便于版主结贴
回复 支持 反对

使用道具 举报

37

主题

132

帖子

422

积分

中级会员

Rank: 3Rank: 3

积分
422
QQ
 楼主| 发表于 2017-8-3 14:30:05 | 显示全部楼层
参考有用的话,我就不会再发帖了。参考后的问题就在上面能解答一下吗?  直接写的语句query里面测试能得到结果,跑起来报错
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'F_product_info' in 'field list'
这个字段要加哪儿去? 麻烦解答一下,谢谢
回复 支持 反对

使用道具 举报

91

主题

13万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
36187
发表于 2017-8-3 14:51:39 | 显示全部楼层
Unknown column 'F_product_info' in 'field list'是数据库中没有找到这个字段

直接写sql,主键就直接用数据库中主键的字段名,不要名表名
远程的联系方法QQ1392416607,添加好友时,需在备注里注明其论坛名字及ID,公司等信息
发远程时同时也发一下帖子地址,方便了解要解决的问题  WeX5教程  WeX5下载



如按照该方法解决,请及时跟帖,便于版主结贴
回复 支持 反对

使用道具 举报

37

主题

132

帖子

422

积分

中级会员

Rank: 3Rank: 3

积分
422
QQ
 楼主| 发表于 2017-8-3 17:06:45 | 显示全部楼层
不清楚实现原理写起来还是很吃力,改过sql第一层可以显示出来了。拷案例代码过去跑,一边调试一边改,还是实现不了。注释有点拗口,读不太懂。
js里面全是undefined
两个js方法:
        Model.prototype.showTreeBeforeRefresh = function(event){//刷新数据
        debugger
                var data = event.source;//等同this,comp("showTree");
            // event.options.parent - 父节点的row
            var parent = event.options && event.options.parent;    //undefined
            //判断如果是叶子节点就返回,不执行查询
            if(data.getValue('fIsLeaves',parent)){       //undefined 进不去
                event.cancel = true;
            }
        };
       
        Model.prototype.showTreeRefreshCreateParam = function(event){//传参
        debugger
                 var data = event.source;
            // event.options.parent - 父节点的row
            var parent = event.options && event.options.parent;     //undefined
            // event.options.append - 数据是否增量加载
            var append = event.options && event.options.append;
            var level = 1;
            //如果存在父,就加载父的下级数据,不存在父加载第一级的数据
            if(parent){
                level = data.getValue('fLevel') + 1;
            }
            var mapParam = new biz.Request.MapParam();
            mapParam.put("parent", parent && parent.getID());
            mapParam.put("level", level);
            event.param.setMap("variables", mapParam);
        };

这是grid的配置
<div component="$UI/system/components/justep/grid/grid" hiddenCaptionbar="true"
          altRows="true" class="x-grid-no-bordered" xid="grid1" data="showTree" appearance="treeGrid"
          expandColumn="fName" cascade="true" directEdit="false" multiselectWidth="80">
          <columns xid="columns2">
            <column width="100" name="fName" editable="true" editor="input" xid="column4"/>
          </columns>
        </div>

几个问题,
          sql = "select fProvinceID as fParentID,2 as fLevel,false as fIsLeaves,"
            +"concat_ws('-','"+parent+"',CONVERT(fID,char)) as fID,fName from "
            + TABLE_CITY+" where fProvinceID = "+parent+" GROUP BY fID limit "+offset+","+limit;
            sqlWhere = "where fProvinceID = "+parent;
            showTable = TABLE_CITY;
            break;
案例里面  fID是自身的id,第一级没有  fParentID,其后所有fParentID指向父级id 。那案例里sql处理fID的函数是干什么的。我肯定是哪里理解差了。另外,存在父就加载父的下级数据具体是什么逻辑,拗口,读不懂。不是通过父级找子级,找到返数据进行渲染,没找到返空吗
出现undefined是因为那里配置错了吗?
回复 支持 反对

使用道具 举报

91

主题

13万

帖子

3万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
36187
发表于 2017-8-3 17:30:48 | 显示全部楼层
确认action方法的table中的关系名给data定义的关系一直吗?

案例中用fID是做分组查询的,可以去掉不用
远程的联系方法QQ1392416607,添加好友时,需在备注里注明其论坛名字及ID,公司等信息
发远程时同时也发一下帖子地址,方便了解要解决的问题  WeX5教程  WeX5下载



如按照该方法解决,请及时跟帖,便于版主结贴
回复 支持 反对

使用道具 举报

37

主题

132

帖子

422

积分

中级会员

Rank: 3Rank: 3

积分
422
QQ
 楼主| 发表于 2017-8-3 18:46:20 | 显示全部楼层
现在数据都能正确加载显示了,谢谢指点。出现了新的问题,第三级目录的数据一旦展开无法收回,请问有人碰到类似的问题吗?对BeX5认识不深,技术有限,排查无力,望继续指点,感激不尽。

展开正常

展开正常

无法收回

无法收回
回复 支持 反对

使用道具 举报

37

主题

132

帖子

422

积分

中级会员

Rank: 3Rank: 3

积分
422
QQ
 楼主| 发表于 2017-8-3 20:58:11 | 显示全部楼层
已解决,代码里第三目录select null as fParentID了,给上相应的fParentID,再保证所有子级目录的fID唯一性,就可以正确的展开和关闭。可以结帖了,谢谢。

效果图

效果图
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2025-7-22 00:09 , Processed in 0.118397 second(s), 33 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表