您可以使用事件偵聽器時被添加到設置像在下面的例子中的值根節點:
請注意,您還可以設置根節點「不可改變」的狀態,以避免價值取消選擇。
/**
* Listener used when root node is added
* In this listener root node is initialized with a value
* and set in immutable state to avoid value deselection.
*
* @param rootNode root node reference when graph is created.
*/
var rootNodeListener = function (rootNode) {
// Change root node type and label with instanceData
rootNode.value = {
type: popoto.graph.node.NodeTypes.VALUE,
label: "Person",
attributes: {name:'Tom Hanks'}
};
// Set node as immutable, in this state the value cannot be deselected.
rootNode.immutable = true;
};
// Add rootNodeListener on NODE_ROOT_ADD event
popoto.graph.on(popoto.graph.Events.NODE_ROOT_ADD, rootNodeListener);
在這裏看到的活生生的例子: http://www.popotojs.com/live/simple-graph/selected-with-event.html
或者因爲1.1.2你可以用一個預定義的圖表(包括選擇的值)作爲啓動功能的參數是這樣開始Popoto:
popoto.start({
label: "Person",
rel: [
{
label: "ACTED_IN",
node: {
label: "Movie",
value: {
title: "The Matrix"
}
}
},
{
label: "DIRECTED",
node: {
label: "Movie"
}
},
{
label: "PRODUCED",
node: {
label: "Movie"
}
},
{
label: "WROTE",
node: {
label: "Movie"
}
}
]
});
活生生的例子在這裏:http://www.popotojs.com/live/results/predefined-data.html
而且這裏更復雜的一個:http://www.popotojs.com/live/save/index.html
謝謝你的回覆。 正如您在示例2中提到的那樣,我能夠使用保存的圖形選項來解決這種情況。但是對於我的場景,選項1看起來更理想,請讓我嘗試一下。特別是讓節點不可變的選項會有很大的幫助。 –