【问题标题】:jsTree - Setting href attributes in Json datajsTree - 在 Json 数据中设置 href 属性
【发布时间】:2012-03-01 09:02:30
【问题描述】:

我正在尝试创建一个“jsTree”树视图,从 .Net 网络服务中获取数据。 一切正常,除了 a-node 的 href 属性。无论我尝试什么,它总是呈现为“#”。 正如我从文档中了解到的那样,任何数据对象中的所有属性都会被复制到 a 节点。

以下是我当前的 json 对象的示例。无论如何都可以弄清楚为什么没有将 href 属性复制到节点?

    [ { "attributes" : { "id" : "rootnode_2",
        "rel" : "root2"
      },
    "children" : [ { "attributes" : { "id" : "childnode_9",
              "rel" : "folder"
            },
          "children" : [ { "attributes" : { "id" : "childnode_23",
                    "rel" : "folder"
                  },
                "children" : null,
                "data" : { "href" : "http://www.google.com",
                    "title" : "Test_Below_1"
                  },
                "state" : null
              } ],
          "data" : { "href" : "http://www.google.com",
              "title" : "Test_1"
            },
          "state" : null
        },
        { "attributes" : { "id" : "childnode_10",
              "rel" : "folder"
            },
          "children" : [ { "attributes" : { "id" : "childnode_24",
                    "rel" : "folder"
                  },
                "children" : null,
                "data" : { "href" : "http://www.google.com",
                    "title" : "Test_Below_2"
                  },
                "state" : null
              } ],
          "data" : { "href" : "http://www.google.com",
              "title" : "Test_2"
            },
          "state" : null
        }
      ],
    "data" : { "href" : "http://www.google.com",
        "title" : "Glatt"
      },
    "state" : "closed"
  } ]

这就是我初始化树的方式;

$("#jstreejson").jstree({
        json_data : {
            "data": treeObject
        },
        themes: {
            "theme": "apple",
            "dots": true,
            "icons": true,
            "url": "/Scripts/themes/apple/style.css"
        },
        plugins: ['core', 'themes', 'json', "json_data"]
    });

【问题讨论】:

    标签: json href jstree


    【解决方案1】:

    所以...我不确定这是否完全正确。据我所知,您无法控制锚属性,但是您可以将内容添加到 json 中的 attr 哈希,然后使用 select_node.jstree 事件打开所需的链接,即:

    .bind("select_node.jstree", function (e,data) {
       var href_address = data.rslt.obj.attr("whatever");
       // open desired link
    }
    

    【讨论】:

    • 尝试将 href 值添加到 attr 哈希而不是 data 哈希。
    猜你喜欢
    • 1970-01-01
    • 2011-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-21
    相关资源
    最近更新 更多