0

我有一个 asp.net mvc4 应用程序,我想在其中添加一个 treeview 。所以我使用了这个 Jquery 库:graphdracula

<html>
  <head>
    <!-- jQuery -->
    <script type="text/javascript" src="~/Content/Scripts/jquery-1.4.2.min.js"></script>
    <!--  The Raphael JavaScript library for vector graphics display  -->
    <script type="text/javascript" src="~/Content/Scripts/raphael-min.js"></script>
    <!--  Dracula  -->
    <!--  An extension of Raphael for connecting shapes -->
    <script type="text/javascript" src="~/Content/Scripts/dracula_graffle.js"></script>
    <!--  Graphs  -->
    <script type="text/javascript" src="~/Content/Scripts/dracula_graph.js"></script>
    <script type="text/javascript" src="~/Content/Scripts/dracula_algorithms.js"></script>
    <script type="text/javascript">
        //Show UCLA CS class dependencies (not complete)
        $(document).ready(function () {
            var width = $(document).width() -500;
            var height = $(document).height();
            var g = new Graph();
            g.edgeFactory.template.style.directed = true;
            g.addEdge("Projet", "Fonction1");
            g.addEdge("Fonction1", "Sous Fonction 1.1");
            g.addEdge("Fonction1", "Sous Fonction 1.2");
            g.addEdge("Projet", "Fonction2");
            g.addEdge("Fonction2", "Sous Fonction 2.1");
            g.addEdge("Fonction2", "Sous Fonction 2.2");
            g.addEdge("Fonction2", "Sous Fonction 2.3");
            g.addEdge("Fonction2", "Sous Fonction 2.4");
            var layouter = new Graph.Layout.Ordered(g, topological_sort(g));
            var renderer = new Graph.Renderer.Raphael('canvas', g, width, height);
        });

    </script>
  </head>
  <body>
    <div id="canvas"></div>
 </body>
</html>

结果是这样的视图: 结果

这很好,但我需要将每个标题更改为这样的链接:@Html.ActionLink("Projet", "Modify_Project")

我怎样才能修改我的代码片段来完成这个任务?

4

1 回答 1

1

如果您使用的是 jQuery。

// on page load
$(function(){

// You need to identify a selector that selects all the titles you want to change..
// Likely they all have a certain class 
$('.titleSelector').changeElementType("a");

// Now you probably want to add an href
$('a.titleSelector').attr('href','http://youlinkhere');

});

这是插件..在 jquery 加载之后和脚本运行之前包含它https://stackoverflow.com/a/8584217/602379

(function($) {
    $.fn.changeElementType = function(newType) {
        var attrs = {};

        $.each(this[0].attributes, function(idx, attr) {
            attrs[attr.nodeName] = attr.nodeValue;
        });

        this.replaceWith(function() {
            return $("<" + newType + "/>", attrs).append($(this).contents());
        });
    };
})(jQuery);
于 2013-10-02T01:40:33.073 回答