本文介绍了ivh树-禁用选择节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ivh树的新手( https://github.com/iVantage/angular-ivh -treeview )并使用该库.我想根据用户权利禁用某些节点以供选择

I am new to ivh tree (https://github.com/iVantage/angular-ivh-treeview) and using this library. I want to disable to certain nodes for selection, based on user entitlement

例如我有这样的树

$scope.bag = [{
            label: 'Glasses',
            value: 'glasses',
            entitled: false,
            children: [{
                label: 'Top Hat',
                value: 'top_hat',
                entitled: true
            }, {
                label: 'Curly Mustache',
                value: 'mustachio',
                entitled: false
            }]
        }];
};

因此,基于标题为[boolean]的变量,应让用户选择或取消选择.该怎么办?

So based on variable entitled: [boolean], it should let user select or unselect. how can this be done?

推荐答案

要实现此目的,您需要将一些逻辑放入自定义节点模板中.这是一个简化的示例,其中我引入了一个辅助程序指令,该指令仅检查node范围值并在需要时禁用其复选框.

To accomplish this you'll need to put some logic into a custom node template. Here's a stripped down example where I've introduced a helper directive that just inspects the node scope value and disables its checkbox if needed.

http://jsbin.com/buqaxu/2/edit?html, js,输出

app.directive('isCbEnabled', function() {
  return {
    link: function(scope, element, attrs) {
      if(scope.node.disabled) {
        element.find('input').attr('disabled', true);
      }
    }
  };
});

您可以在模板的ivh-treeview-checkbox指令中附加类似的内容.请注意,node是模板中受支持的范围变量.

You'd could attach something like this to your the ivh-treeview-checkbox directive in your template. Note that node is a supported scope variable within templates.

这篇关于ivh树-禁用选择节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 04:18