English 中文(简体)
jsTree: Prevent before and after TYPE, only use inside
原标题:

I am using jsTree which is very nice. When dragging and dropping, I don t really care for the before and after types, I only want to use inside. Meaning, I am only concerned about that parent that a child is dropped into, rather than where the order is with other elements INSIDE the parent.

So, I wanted to build my callback, so it always refers to the parent node that it is inside. But, it is not fool proof, yet.

onmove : function (NODE,REF_NODE,TYPE,TREE_OBJ,RB) {
    if (TYPE ==  inside ) {
        alert( Item to move: +$(NODE).attr( rel )+  to  +$(REF_NODE).attr( rel )+   +TYPE);
    } else if (TYPE ==  after ) {
        alert( Item to move: +$(NODE).attr( rel )+  to  +$(REF_NODE).parent().parent( li ).attr( rel )+   +TYPE);
    }
},

Does anyone have suggestions, how I can change my callback, so that the REF_NODE is always the parent that the NODE is moved into? Rather than a sibling of, which is a child of the parent?

Here is an example on jsbin: http://jsbin.com/uroye3/2

When trying the example, drag other folders onto the Templates folder. You SHOULD be alerted that you are moving the other folders into folder 4. But, if you try different before and after drags into the Templates folder, you sometimes get undefined. So, the results are not always as expected. Like I said, I just always want to know the parent folder, in this case 4, that another folder is dropped into.

问题回答

Taken from the jstree FAQ, this may be of help to you:

When moving or creating node “inside” another node, the callback REF_NODE does not point to the new parent node. What to do?

This is not a bug! Because you can create nodes at a specific position among the parent node’s children, passing only the parent node will not be enough. This is why you must always check the TYPE argument passed to the callbacks! If you want to always work with the parent node – add this line at the top of the callbacks:

if(TYPE != "inside") { 
  TYPE="inside"; 
  REF_NODE = $(NODE).parents("li:eq(0)").get(0); 
}




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签