2013-10-01 28 views
0

我有一個asp.net mvc4應用程序,我想在其中添加一個treeview。所以我用這個jQuery庫:graphdracula將標籤更改爲jQuery庫中的鏈接

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

的結果是這樣的觀點: result

這是件好事,但我需要每個標題改爲像這樣的鏈接:@Html.ActionLink("Projet", "Modify_Project")

我如何修改我的代碼片段來完成這項任務?

回答

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