jQuery MiniUI

标题: 请问tree的单选按钮如何设置默认选中的值。。 [打印本页]

作者: wise    时间: 2017-1-21 22:42:08     标题: 请问tree的单选按钮如何设置默认选中的值。。

本帖最后由 wise 于 2017-1-21 23:07 编辑

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

[attach]8772[/attach]

我用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渲染是这么写的。

作者: dforce    时间: 2017-1-22 09:30:12

drawnode事件不处理选中不选中
请直接在js里设置tree.setValue(value)
作者: wise    时间: 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里面写,,单选按钮也选不中。。
作者: dforce    时间: 2017-1-23 09:19:07

wise 发表于 2017-1-22 21:21
var leftTree=mini.get("authentication_tree");
   
    //设置左侧tree默认值

[attach]8775[/attach]请确保有value是"158"的节点。
作者: wise    时间: 2017-1-23 09:43:13

dforce 发表于 2017-1-23 09:19
请确保有value是"158"的节点。

158是json数据中的id字段。
作者: dforce    时间: 2017-1-23 10:01:22

wise 发表于 2017-1-23 09:43
158是json数据中的id字段。

如我上面的截图,ajax的节点的id是ajax,可以正常使用setValue选中
你这请将id当作字符串,setValue("158")
作者: wise    时间: 2017-1-23 10:42:06

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

其怪了,我就是设置不上去。。。
作者: wise    时间: 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>
复制代码
我是这么写的,就是设不上去。。。如果设置成多选是可以设置上去的,单选就是设置不上去。  默认的选中状态就是没法设置上去,设置是设置上去了,但是样式没变化,样式没有选上。。

作者: dforce    时间: 2017-1-23 11:03:51

wise 发表于 2017-1-23 10:43
我是这么写的,就是设不上去。。。如果设置成多选是可以设置上去的,单选就是设置不上去。  默认的选中状 ...

请提供数据,html+js代码重现出你说的问题
作者: wise    时间: 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样式应该是有个绿色的点。。

作者: dforce    时间: 2017-1-23 12:05:00

wise 发表于 2017-1-23 11:08
json:

不是让你不要在ondrawnode事件里处理,为什么还在里面处理
请在js里直接写
作者: wise    时间: 2017-1-23 14:42:34

本帖最后由 wise 于 2017-1-23 14:59 编辑
dforce 发表于 2017-1-23 12:05
不是让你不要在ondrawnode事件里处理,为什么还在里面处理
请在js里直接写

直接写更惨,默认值设都设不上去,选不上。。。。。。。。。判断那个是默认值,我还得用到json的checked,写在重绘里面没什么不妥啊。。。值只有一个,只不过重绘是不停的循环而已。。
=====================
直接写js的代码。。。。更惨。。什么反应都没有。。

var leftAuthenticationTypeTree=mini.get("authentication_object_type_tree");
//设置左侧tree默认值
leftAuthenticationTypeTree.setValue("158");
作者: dforce    时间: 2017-1-23 16:08:14

wise 发表于 2017-1-23 14:42
直接写更惨,默认值设都设不上去,选不上。。。。。。。。。判断那个是默认值,我还得用到json的checked, ...

[attach]8776[/attach]用的你的代码和数据,可以正常选中,如果你还有问题,请按示例修改,并且更新到最新版本
作者: wise    时间: 2017-1-23 16:38:49

dforce 发表于 2017-1-23 16:08
用的你的代码和数据,可以正常选中,如果你还有问题,请按示例修改,并且更新到最新版本 ...

和代码没关系,原来是miniui.js的问题。。。我的是16年的版本。。汗。。。。。谢谢你们哦。。新年快乐




欢迎光临 jQuery MiniUI (http://miniui.com/discuss/) Powered by Discuz! X2