0

我正在尝试动态更改 Nativescript Angular App 的 RadListView Ui 列表中 itemReorder 布尔值的值,但没有成功。每次我都会收到此错误:行为未附加到 RadListView,请使用 RadListView addbehavior 方法附加它。

HTML:

<GridLayout  tkExampleTitle tkToggleNavButton class="proposedLettersRow">
        <RadListView #itemReord [items]="items" selectionBehavior="LongPress" reorderMode = "Drag" [itemReorder]="itemReorder" (itemReordered)="onItemReordered($event)" multipleSelection= "false"
                    >
                <ng-template tkListItemTemplate let-item="item">
                    <GridLayout class="listItemTemplateGrid" >
                        <Label
                            [text]="item"
                            [ngClass]="!isWin ?  'proposed' : 'proposedIsDone'"
                            class="list-group-item ">
                        </Label>
                    </GridLayout>
                </ng-template>

                <ListViewGridLayout tkListViewLayout
                                    scrollDirection="Vertical"
                                    height="150"
                                    ios:itemHeight="150"
                                    spanCount="7"
                                    horizontalAlignment="center">
                </ListViewGridLayout>
        </RadListView>
    </GridLayout>

打字稿:

一开始this.itemReorder设置为true,然后一个函数将其更改为false,执行此函数时出现错误。

终端日志

代码

4

1 回答 1

0

我认为你设置itemReorderfalse太早了,可能是组件需要它trueitemReordered事件中。由于它还不是开源的,所以我没有太多关于这方面的信息。但是一个简单的解决方法是添加超时,

public youWin() {
    if (this.newIndex < this.oldIndex) {
        setTimeout(() => {
            this.itemReorder = false;
        }, 100);
    }
}

更新游乐场

于 2019-01-20T14:03:49.987 回答