jQuery MiniUI

 找回密码
 立即注册
查看: 5193|回复: 13
打印 上一主题 下一主题

请问tree的单选按钮如何设置默认选中的值。。 [复制链接]

Rank: 4

跳转到指定楼层
楼主
发表于 2017-1-21 22:42:08 |只看该作者 |倒序浏览
本帖最后由 wise 于 2017-1-21 23:07 编辑

请问tree是单选按钮如何设置默认选中的值。。



我用tree.selectNode('158');都试了,都没办法设置默认选中。。。

function onTreeDraw(e){
    var tree = e.sender;
    var node = e.node;
    if(node.checked){
        tree.selectNode(node.resource_id);
    }
    //阻止父节点
    if (tree.hasChildren(node)) {
        e.cancel = true;
    }
}
我的tree渲染是这么写的。
附件: 你需要登录才可以下载或查看附件。没有帐号?立即注册

Rank: 8Rank: 8

沙发
发表于 2017-1-22 09:30:12 |只看该作者
drawnode事件不处理选中不选中
请直接在js里设置tree.setValue(value)

Rank: 4

板凳
发表于 2017-1-22 21:21:36 |只看该作者
dforce 发表于 2017-1-22 09:30
drawnode事件不处理选中不选中
请直接在js里设置tree.setValue(value)

var leftTree=mini.get("authentication_tree");
   
    //设置左侧tree默认值
    leftTree.setValue(158);
-------
我直接在js里面写,,单选按钮也选不中。。

Rank: 8Rank: 8

地板
发表于 2017-1-23 09:19:07 |只看该作者
wise 发表于 2017-1-22 21:21
var leftTree=mini.get("authentication_tree");
   
    //设置左侧tree默认值

请确保有value是"158"的节点。
附件: 你需要登录才可以下载或查看附件。没有帐号?立即注册

Rank: 4

5#
发表于 2017-1-23 09:43:13 |只看该作者
dforce 发表于 2017-1-23 09:19
请确保有value是"158"的节点。

158是json数据中的id字段。

Rank: 8Rank: 8

6#
发表于 2017-1-23 10:01:22 |只看该作者
wise 发表于 2017-1-23 09:43
158是json数据中的id字段。

如我上面的截图,ajax的节点的id是ajax,可以正常使用setValue选中
你这请将id当作字符串,setValue("158")

Rank: 4

7#
发表于 2017-1-23 10:42:06 |只看该作者
dforce 发表于 2017-1-23 10:01
如我上面的截图,ajax的节点的id是ajax,可以正常使用setValue选中
你这请将id当作字符串,setValue("158" ...

其怪了,我就是设置不上去。。。

Rank: 4

8#
发表于 2017-1-23 10:43:50 |只看该作者
本帖最后由 wise 于 2017-1-23 10:58 编辑
dforce 发表于 2017-1-23 10:01
如我上面的截图,ajax的节点的id是ajax,可以正常使用setValue选中
你这请将id当作字符串,setValue("158" ...
  1. <ul id="authentication_object_type_tree" class="mini-tree" url="mmmm.jsp" dataField="result" valueField="dictionary_id" parentField="dictionary_root_id" textField="dictionary_name" showTreeIcon="true" resultAsTree="false" showRadioButton="true" showFolderCheckBox="false" expandOnLoad="true" onNodeSelect="onLeftTypeTreeClick" onDrawNode="onLeftTypeTreeDraw"></ul>
复制代码
我是这么写的,就是设不上去。。。如果设置成多选是可以设置上去的,单选就是设置不上去。  默认的选中状态就是没法设置上去,设置是设置上去了,但是样式没变化,样式没有选上。。

Rank: 8Rank: 8

9#
发表于 2017-1-23 11:03:51 |只看该作者
wise 发表于 2017-1-23 10:43
我是这么写的,就是设不上去。。。如果设置成多选是可以设置上去的,单选就是设置不上去。  默认的选中状 ...

请提供数据,html+js代码重现出你说的问题

Rank: 4

10#
发表于 2017-1-23 11:08:14 |只看该作者
本帖最后由 wise 于 2017-1-23 11:10 编辑
dforce 发表于 2017-1-23 11:03
请提供数据,html+js代码重现出你说的问题

json:
  1. {"status":"success","result":[{"resource_dictionary_id":159,"resource_dictionary_key":"authentication
  2. .object_type.self","resource_dictionary_name":"访问者(自己)","resource_dictionary_status":1,"resource_dictionary_root_id"
  3. :155,"isLeaf":1,"checked":"true"},{"resource_dictionary_id":158,"resource_dictionary_key":"authentication
  4. .object_type.user_role","resource_dictionary_name":"用户角色","resource_dictionary_status":1,"resource_dictionary_root_id"
  5. :155,"isLeaf":1,"checked":"false"},{"resource_dictionary_id":157,"resource_dictionary_key":"authentication
  6. .object_type.user_group","resource_dictionary_name":"用户组","resource_dictionary_status":1,"resource_dictionary_root_id"
  7. :155,"isLeaf":1,"checked":"false"},{"resource_dictionary_id":156,"resource_dictionary_key":"authentication
  8. .object_type.user_acount","resource_dictionary_name":"用户账户","resource_dictionary_status":1,"resource_dictionary_root_id"
  9. :155,"isLeaf":1,"checked":"false"}]}
复制代码


树代码:
  1. <ul id="authentication_object_type_tree" class="mini-tree" url="mmmm.jsp" dataField="result" valueField="resource_dictionary_id" parentField="resource_dictionary_root_id" textField="resource_dictionary_name" showTreeIcon="true" resultAsTree="false" showRadioButton="true" showFolderCheckBox="false" expandOnLoad="true" onNodeSelect="onLeftAuthenticationTypeTreeClick" onDrawNode="onLeftAuthenticationTypeTreeDraw"></ul>
复制代码


js代码:
  1. function onLeftAuthenticationTypeTreeDraw(e){
  2.     //console.log(e);
  3.     var tree = e.sender;
  4.     var node = e.node;
  5.     if(node.checked){//调试提示        systemCore.tips('i','选中'+node.resource_dictionary_id);//设置选中
  6.         tree.selectNode(node.resource_dictionary_id.toString());
  7.         //tree.selectNode("159");
  8.     }
  9.     //阻止选择父节点
  10.     if (tree.hasChildren(node)) {
  11.         e.cancel = true;
  12.     }
  13. }
复制代码
默认已经设置上了,因为浏览器直接提示设置默认值成功,,但是样式就是不会变。。单选选中的时候tree样式应该是有个绿色的点。。

Archiver|普加软件

GMT+8, 2024-6-2 13:17 , Processed in 1.041864 second(s), 10 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部