adding rel tag/disable links in jsTree

天大地大妈咪最大 提交于 2019-12-08 07:48:19

问题


Am trying to add a rel tag to all rels that are empty for jsTree. I have managed to get this to work in jsFiddle, but when trying to apply the same code to the full tree, it does not work (that is, the rel tag still is blank/empty). I grabbed the resulting source code from my tree to use as this example, which is why am confused that the code is not working.

Here is the working jsFiddle version: view here.

Also, would it be possible that if the rel='disabled', to remove or disable the a href so that the link is disabled?


回答1:


To those curious, I did a couple of things -

  1. I updated in the database for all my links to be specific types (ie, folder) that I wanted disabled. A blank rel tag also worked. If you can't access a database, I also tried the following piece of code that applied to the .bind("before.jstree"):

    $('li[rel=""]').attr('rel','disabled');
    
  2. I applied a bind to the jsTree instance. The following code is what I used,

    .bind("before.jstree", function (e, data) {
     $('ul li[rel="file"] > a').each(function() {
      $(this).contents().unwrap();
     });
    })
    

This unwraps the links that have rel="file" (satisfying the need to make nodes unclickable. You can set the rel tag to anything else that you want to have unwrapped.

Edit: I've also made it even simpler, by just disabling single and double-clicking, like so:

   .bind("before.jstree", function (e, data) {
    $('ul li[rel="file"] > a').each(function() {
      $(this).click(false);
      $(this).dblclick(false);
     });
    })

I hope this helps!



来源:https://stackoverflow.com/questions/10853378/adding-rel-tag-disable-links-in-jstree

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!