我正在尝试为https://github.com/RubaXa/Sortable编写一个aurelia附加行为,它允许使用html 5拖放重新排序列表中的项目,类似于它们为AngularJS设置的命令。到目前为止,html元素的拖放操作非常好,可以使用以下模板代码
<template>
<require from="./sortable"></require>
<section>
<h2>${title}</h2>
<ul sortable>
<li repeat.for="item of items">${item.title}</li>
</ul>
</section>
</template>附属物行为
import {Behavior} from 'aurelia-framework';
import Sortable from 'rubaxa-sortable';
export class SortableAttachedBehavior {
static metadata() {
return Behavior
.attachedBehavior('sortable');
}
static inject() {
return [Element];
}
constructor(element) {
this.element = element;
}
bind(viewModel) {
this.sortable = Sortable.create(this.element);
}
unbind() {
this.sortable.destroy();
this.sortable = null;
}
}作为下一步,除了重新排序html元素之外,我还想重新排序模型中的数据项。我可以从我拥有的可排序实例中获取有关dnd的所需事件。我现在的问题是如何获得对这些项目的参考。
因为我只想在子元素上存在repeat.for行为时才这样做,所以我认为最好的方法是访问它的重复实例并更新其items属性的内容。但是,如何检查这种附加行为的存在,以及如何获得重复实例?
或者,是否有更好的方法来访问这些项(除了将它们指定为我的可排序行为的属性之外)?
干杯,蒂尔曼
发布于 2018-03-11 12:37:41
已经有相应的插件,例如https://github.com/buttonwoodcx/bcx-aurelia-reorderable-repeat
您可以通过查看@源代码(-:
https://stackoverflow.com/questions/29435832
复制相似问题