我有一个带拖放模块的角度项目。现在,我的可拖动列表包含在对象数组中,如下所示:
vegetables = [
{name: 'Carrot', type: 'vegetable'},
{name: 'Onion', type: 'vegetable'},
{name: 'Potato', type: 'vegetable'},
{name: 'Capsicum', type: 'vegetable'}];
我在我的组件中展示它,就像这样:
<div class="list-group">
<li class="list-group-item list-group-item-action list-group-item-success" [draggable]
*ngFor="let item of vegetables" [dragClass]="'active'" [dragTransitClass]="'active'"
[dragData]="item" [dragScope]="item.type" [dragEnabled]="dragEnabled">
{{item.name}}
</li>
</div>
问题是每次我从
vegetables
列表,我想展示一个新的蔬菜列表。
所以我试着这样做:
vegetables = [
{name: 'Carrot', type: 'vegetable'},
{name: 'Onion', type: 'vegetable'},
{name: 'Potato', type: 'vegetable'},
{name: 'Capsicum', type: 'vegetable'}],
[
{name: 'Carrot2', type: 'vegetable'},
{name: 'Onion2', type: 'vegetable'},
{name: 'Potato2', type: 'vegetable'},
{name: 'Capsicum2', type: 'vegetable'}
];
里面有多个物体阵列
蔬菜
变量
但问题是我不知道如何在我的组件模板中显示它。我试过这个:
<li class="list-group-item list-group-item-action list-group-item-success"
[draggable] *ngFor="let item of vegetables[i]" ...>
哪里
i
每次我从中拖放一次,它都是增量变量
蔬菜
列表会递增,但它当然不是这样工作的,我不知道正确的方法。
那么,我如何遍历内部的多个数组呢
蔬菜
每次拖放时呈现一个新的蔬菜列表?
感谢您的帮助。