在jsTree中添加rel标签/禁用链接 [英] adding rel tag/disable links in jsTree

查看:100
本文介绍了在jsTree中添加rel标签/禁用链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Am试图向所有jsTree空的rels添加一个rel标签.我已经设法使它在jsFiddle中工作,但是当尝试将相同的代码应用于完整树时,它不起作用(也就是说,rel标签仍然为空/空).我从树上获取了生成的源代码以用作本示例,这就是为什么对代码无法正常工作感到困惑的原因.

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.

这是有效的jsFiddle版本:在此处查看.

Here is the working jsFiddle version: view here.

此外,如果rel ='disabled'是否有可能删除或禁用a href从而禁用链接?

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

推荐答案

对于那些好奇的人,我做了几件事-

To those curious, I did a couple of things -

  1. 我已在数据库中将所有链接更新为要禁用的特定类型(即文件夹).空白的rel标签也可以使用.如果您无法访问数据库,我还尝试了以下适用于.bind("before.jstree")的代码:

  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');

  • 我将绑定应用于jsTree实例.以下代码是我使用的代码,

  • 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();
     });
    })
    

  • 这将解开具有rel ="file"的链接(满足节点不可点击.您可以将rel标签设置为您要解包的其他任何内容.

    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.

    我也通过禁用一次和双击使它变得更加简单,就像这样:

    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);
         });
        })
    

    我希望这会有所帮助!

    这篇关于在jsTree中添加rel标签/禁用链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆