jsPlumb: no se puede hacer clic () en un div dentro de un div que actúa como una fuente/objetivo jsPlumb
Frecuentes
Visto 967 equipos
2
Estoy usando jsplomada.
My current functionality lets me create a .project
div that can then have .task
divs inside it. The .project
div has 3 clickable buttons which all work using jQuery and the .task
s dentro del .project
have a single close button which also works.
As can we seen here: http://jsfiddle.net/9yej6/3/
(click the add project button then click on the green project and try to click on the X near some task - an alert should pop up)
However, whenever I try to make the .task
s una makeTarget
/makeSource
using jsPlumb it surpasses (probably not the best word) any other event done by jQuery. That is when I click on the X icon of the .task
it instead acts as if I click on the .task
itself and tries to create jsPlumb's bond.
Como se puede ver aquí: http://jsfiddle.net/9yej6/4/
So the following line no longer works (note I'm using the on()
function since the .project
/.task
divs are dynamically created):
$("#container").on('click','.task .close',function(e) { alert('a task`s add was clicked'); });
Inicialmente el addTask()
function was (which worked, but you can't add jsPlumb bonds):
function addTask(parentId, index) { var newState = $('<div>').attr('id', 'state' + index).addClass('task'); var close = $('<div>').addClass('close'); newState.append(close); var title = $('<div>').addClass('title').text('task ' + index);; newState.append(title); $(parentId).append(newState); }
Pero cuando agrego el makeTarget()
/makeSource()
calls to it, it seems to surpass any other jQuery event handling. Where my new addTask()
la función se convierte en:
function addTask(parentId, index) { var newState = $('<div>').attr('id', 'state' + index).addClass('task'); var close = $('<div>').addClass('close'); newState.append(close); var title = $('<div>').addClass('title').text('task ' + index);; newState.append(title); $(parentId).append(newState); jsPlumb.makeTarget(newState, { anchor: 'Continuous' }); jsPlumb.makeSource(newState, { anchor: 'Continuous' }); }
2 Respuestas
3
También puedes utilizar la filter
parameter to specify what element to be included for the object drag.
See my complete answer aquí.
http://jsplumbtoolkit.com/doc/connections.html#sourcefilter
jsPlumb.makeSource("foo", {
filter:":not(a)"
});
Above means, don't interfere with operations related to a (anchor tag)
.
contestado el 23 de mayo de 17 a las 11:05
2
Como se mencionó,
$("#container").on('click','.task .close',function(e) {
alert('a task`s add was clicked');
});
This code doesn't work becasue you have made the '.task' element as either objetivo or fuente part of jsPlumb hence the mouse events will be handled by jsPlumb which prevents the default event handling(jQuery or pure JS) of those elements.
In such case you need to create a small rectangle DIV(refer image) from where the user can drag the connection instead of an entire DIV.
contestado el 29 de mayo de 14 a las 01:05
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas javascript jquery jsplumb or haz tu propia pregunta.