I am trying to find a way to create a child node (with .jstree("create", null, "inside", ....).
But this will create a new node as the last of all existing children.
Is it possible to force to add the new node as the (new) first child?
I used this code:
$('#jstree').jstree(true).create_node('#', //parent node, '#' for root
"new first node", //data of the node
"first" //position of the new node: first, last
);
Also please check out the jsTree API.
HTH
Related
jstree version 3.1.1, plugin dnd.
I need to drag nodes in one jstree element and drop them to another jstree element. This is working fine and i get all information about the element which is dragged, but I don't get any information about the dropped (newly) created node in the second jstree element.
dnd_stop.vakata seems not to contain this information (at least i can't find it), create_node.jstree isn't triggered, when dnd creates a new node, so i wonder how to get the id of the new node.
Please check this one: http://jsfiddle.net/amug08ms/
all needed code is in the example ...
When you drag a node from the upper jstree to the lower jstree, all information about that node is lost, except the text of the node. So how can i add the information i need to the dropped (created) node in the lower jstree node?
Thanks for any hint in advance!
The event that is triggered when using multi-tree drag'n'drop is copy_node.jstree.
Here is how you can transfer the ID (using this example it should be easy to copy any other properties you may need - by default IDs and data is not copied):
$('#destTree').on('copy_node.jstree', function (e, data) {
data.instance.set_id(data.node, data.original.id);
for(var i = 0, j = data.node.children_id; i < j; i++) {
data.instance.set_id(data.node.children_d[i], data.original.children_d[i]);
}
});
Here is the updated fiddle:
http://jsfiddle.net/amug08ms/1/
I have dropdown where the values of options are like jcr:content/jcr:title, jcr:content/jcr:description, /jcr:content/par/entry/text etc. Here the last one is the property of parent, like jcr:title is the property of jcr:content node & text is the property of entry node, but entry has parent par and par has parent jcr:content. I am at the page node and using the below code to fetch such values which doesn't work :
Node n = (Node)nodeIter.next();
log.info(n.getProperty("/jcr:content/par/entry/text"));
Any Idea how to get values in such a way.
Thanks
Remove the starting slash from the property path. It makes the path absolute while you are interested in the relative one (as in other examples you've described):
n.getProperty("jcr:content/par/entry/text");
I am trying to check at which node the cursor / selection is.
I want to get the
node name
html inside the node
The node can be accessed using:
tinyMCE.activeEditor.selection.getNode()
And there are 2 properties that will return the wanted values: nodeName and innerHTML
tinyMCE.activeEditor.selection.getNode().nodeName
tinyMCE.activeEditor.selection.getNode().innerHTML
I am using Treegrid widget of smartgwt.
I want to copy selected(partial) tree structure(leaf node to root node) from existing Treegrid to other TreeGrid.
I got ID's of selctedPath like "4/135/1456" from TreeGrid and Name of selected leaf node.
TreeGrid requires dataUrl( xml ) How to pass data of selected(partial) tree structure to 2nd TreeGrid ?
Is there any API for this case ?
User can add different partial tree in 2nd TreeGrid.
How to set this data to 2nd TreeGrid ?
Any help or guidance in this matter would be appreciated.
On your first TreeGrid use the getTree() methods to retrieve its underlying Tree object. There, use the available methods to retrieve an array of TreeNode objects for the required nodes you want to move over to the 2nd TreeGrid, e.g. getParents(TreeNode node), getDescendants(TreeNode node) etc. On the 2nd TreeGrid you can again call the getTree() and there use the add nodes methods, like the addList(TreeNode[] nodeList, TreeNode parent).
You can acheive the same with using drag and drop facility. In this you need not to use dataURL(XML). Try this..
http://www.smartclient.com/smartgwt/showcase/#tree_interaction_drag_nodes
I am trying to figure out how to get the name of the parent from a text node's scope.
//text()[name(parent)='p']
How can you get the name of the current node's parent?
If you're trying to test the name, you almost had it:
//text()[name(parent::*)='p']
If you're trying to return the name:
name(//text()/parent::*)
FYI, point of terminology: a text node is not an element.
Anyway, the most succinct way to select the parent of the current node is ..
So, the name of the parent element of the current node (which could be a text node) is name(..)
Substituting that into your XPath expression:
//text()[name(..)='p']
But a less roundabout way to write that would be
//p/text()
(assuming the p elements in the document have no namespace prefix). Either way, you're selecting all text nodes that are children of elements named p.
//text/..[#name='p']
This will get all parents of <text> nodes as long as the parent has a name attribute of p.