简体   繁体   中英

ivh tree - disable node for selection

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

for example i have tree like this

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

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

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,output

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM