1
我用dynatree.js創建了一個js樹。我有一個很長的等級。該樹顯示負載上擴大。我想樹應該擴大到一個層次。下面是我的代碼dynatree js顯示最初展開的樹
<apex:component controller="TreeViewController">
<apex:attribute name="roleOrUserId" required="true" type="String" assignTo="{!roleOrUserId}" description="Enter Role or User Id to build the hierarchy. Pass null if you are passing JSON data as a parameter" />
<apex:attribute name="selectable" type="Boolean" assignTo="{!selectable}" description="Do you want nodes to be selectable?" />
<apex:attribute name="value" type="String" description="IDs of selected Nodes in CSV format" />
<apex:attribute name="JsonData" type="String" assignTo="{!JsonData}" description="JSON input for the tree component" />
<apex:inputHidden id="selectedKeys" value="{!value}" />
<!--<apex:includeScript value="{!URLFOR($Resource.DynaTree, 'jquery/jquery.js')}" /> -->
<apex:includescript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"/>
<apex:includeScript value="{!URLFOR($Resource.DynaTree, 'jquery/jquery-ui.custom.js')}" />
<apex:includeScript value="{!URLFOR($Resource.DynaTree, 'jquery/jquery.cookie.js')}" />
<apex:includeScript value="{!URLFOR($Resource.DynaTree, 'src/jquery.dynatree.js')}" />
<!--<apex:includeScript value="{!$Resource.DynaTreeJs}" /> -->
<apex:stylesheet value="{!URLFOR($Resource.DynaTree, 'src/skin/ui.dynatree.css')}" />
<!-- Add code to initialize the tree when the document is loaded: -->
<script type="text/javascript">
$.noConflict();
$(document).ready(function() {
$(function(){
// Attach the dynatree widget to an existing <div id="tree"> element
// and pass the tree options as an argument to the dynatree() function:
$("#tree").dynatree({
onActivate: function(node) {
// A DynaTreeNode object is passed to the activation handler
// Note: we also get this event, if persistence is on, and the page is reloaded.
//alert("You activated " + node.data.key);
},
persist: false,
checkbox: true,
generateIds: false,
classNames: {
checkbox: "dynatree-checkbox",
expanded: "dynatree-expanded"
},
selectMode: 3,
children: {!JsonString},
onSelect: function(select, node) {
// Get a list of all selected nodes, and convert to a key array:
var selKeys = $.map(node.tree.getSelectedNodes(), function(node){
return node.data.key;
});
jQuery(document.getElementById("{!$Component.selectedKeys}")).val(selKeys.join(", "));
// Get a list of all selected TOP nodes
var selRootNodes = node.tree.getSelectedNodes(true);
// ... and convert to a key array:
var selRootKeys = $.map(selRootNodes, function(node){
return node.data.key;
});
},
});
});
});
</script>
<!-- Add a <div> element where the tree should appear: -->
<div id="tree"> </div>
</apex:component>
輸出
開放,直到最後一級的所有子節點的樹狀視圖。我只想打開第一層。如何做達。有沒有設置或其他什麼?請幫助
嗨,我添加了minExpandLevel,但它不起作用。它也沒有在瀏覽器的錯誤控制檯中顯示任何js錯誤。 – user2085984 2013-02-19 12:44:24
另外,在你的數據項中,確保你已將'expand'屬性設置爲false。也許'minExpandLevel'不是你正在尋找的,因爲它會使一級節點不可摺疊。 – 2013-02-19 14:45:57