knockout.js - How do I swap two items in an observableArray? -
knockout.js - How do I swap two items in an observableArray? -
i have button moves item 1 position left in observablearray. doing next way. however, drawback categories()[index] gets removed array, discarding whatever dom manipulation (by jquery validation in case) on node.
is there way swap 2 items without using temporary variable preserve dom node?
moveup: function (category) { var categories = viewmodel.categories; var length = categories().length; var index = categories.indexof(category); var insertindex = (index + length - 1) % length; categories.splice(index, 1); categories.splice(insertindex, 0, category); $categories.trigger("create"); }
here's version of moveup
swap in 1 step:
moveup: function(category) { var = categories.indexof(category); if (i >= 1) { var array = categories(); categories.splice(i-1, 2, array[i], array[i-1]); } }
that still doesn't solve problem, though, because knockout still see swap delete , add together action. there's open issue knockout back upwards moving items, though. update: of version 2.2.0, knockout recognize moved items , foreach
binding won't re-render them.
knockout.js
Comments
Post a Comment