【发布时间】:2016-12-01 04:50:19
【问题描述】:
我使用了一些不错的 simple drag-and-drop library from github,并且我有一个视图,其中包含 3 个不同的按钮,每个按钮在同一个地方但不是在同一时间被点击时都会显示一个列表。
由于某种原因,只有第一个列表可以排序,但其他 2 个不能排序...我可以移动对象但它们不可放置,因此我无法更改顺序。
这是我的html:
<div>
<!-- list 1 button -->
<button md-button
(click)="showFirstList()"
class="md-primary">List 1
</button>
<!-- list 2 button -->
<button md-button
(click)="showSecondList()"
class="md-primary">List 2
</button>
<!-- list 3 button -->
<button md-button
(click)="ThirdList()"
class="md-primary">List 3
</button>
</div>
<md-content>
<div *ngIf="showingListOne">
<div dnd-sortable-container [dropZones]="['zone-one']" [sortableData]="listOneToDisplay | async">
<div class="list-bg" *ngFor="#item of listOneToDisplay | async; #i = index" dnd-sortable [sortableIndex]="i">
ID: {{item.id}} <p></p> name: {{item.name}}
</div>
</div><br><br>
</div>
<div *ngIf="showingListTwo">
<div dnd-sortable-container [dropZones]="['zone-two']" [sortableData]="listTwoToDisplay | async">
<div class="list-bg" *ngFor="#item of listTwoToDisplay | async; #i = index" dnd-sortable [sortableIndex]="i">
ID: {{item.id}} <p></p> age: {{item.age}}
</div>
</div>
</div>
<div *ngIf="showingListThree">
<div dnd-sortable-container [dropZones]="['zone-three']" [sortableData]="listThreeToDisplay | async">
<div class="list-bg" *ngFor="#item of listThreeToDisplay | async; #i = index" dnd-sortable [sortableIndex]="i">
ID: {{item.id}} <p></p> age: {{item.age}}
</div>
</div>
</div>
</div>
</md-content>
这是我的排序列表.component.ts:
@Component({
selector: 'sorting-lists',
styles: [require('./sorting-lists.css')],
directives: [DND_DIRECTIVES],
providers: [DND_PROVIDERS],
template: require('./sorting-lists.component.html')
})
@Injectable()
export class MyCmp implements OnInit {
listOneToDisplay = this._myService.getFirstListData();
listTwoToDisplay = this._myService.getSecondListData();
listThreeToDisplay = this._myService.getThirdListData();
showingListOne = false;
showingListTwo = false;
showingListThree = false;
constructor(private _myService: MyService) {
};
public showFirstList(): void {
this.showingListOne = true;
this.showingListTwo = false;
this.showingListThree = false;
}
public showSecondList(): void {
this.showingListTwo = true;
this.showingListOne = false;
this.showingListThree = false;
}
public showThirdList(): void {
this.showingListThree = true;
this.showingListTwo = false;
this.showingListOne = false;
}
}
如果有人能帮我弄清楚为什么只有第一个是可排序的,那将是幸运的!
谢谢:)
【问题讨论】:
-
把这段代码放到plunkr中,方便调试
标签: javascript html typescript angular angular2-routing