简体   繁体   中英

knockout-sortable 'dragged' callback not working

I am trying to adapt the example fiddle from the knockout-sortable in order to use the 'dragged' callback instead of the default 'clone' function.

http://jsfiddle.net/mp2k170t/1/

I've added a 'makeNewTask' method to the root viewmodel like this:

self.makeNewTask = function(task, event, ui) {
    alert('make new task');
    return new Task(task.name() + " (created by makeNewTask)");
}

I am trying to bind to it by using this:

<div class="item" data-bind="draggable: { data: newTask, isEnabled: allowNewTask, dragged: $root.makeNewTask }">

However, the clone method is still being called. What am I doing wrong?

dragged callback is only available in sortable binding.

If you change sortable binding as

<div class="container" data-bind="sortable: {data: tasks, dragged: $root.makeNewTask}">

and draggable binding as

<div class="item" data-bind="draggable: { data: newTask, isEnabled: allowNewTask  }">

should work. Use dragged as an alternative to clone . So you might consider removing the clone method from prototype if using dragged option.

Fiddle

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM