首页 > 解决方案 > ValueList Dropdown 中的类型不存在属性“push”

问题描述

Hai 正在使用本机 script-angular 开发 android 和 ios 应用程序。我在我的应用程序中使用了 nativescript-drop-down 插件。我使用 valuelist 数组在下拉列表中绘制值。但是值列表返回错误,例如“ValueList Dropdown 中的类型不存在属性'push'”。我不知道这个问题是如何出现的。帮我解决问题。

我的示例代码:

我的HTML:

<StackLayout orientation="vertical">
    <DropDown [items>="items"></DropDown>   
</StackLayout>

我的组件 ts 文件:

import { Component } from "@angular/core";
import {ValueList} from "nativescript-drop-down";


@Component({
    selector: "my-app",
    templateUrl:"app.component.html",
})

export class AppComponent {
    public items:ValueList<string>;

        constructor() {
        this.items = [];
         for(var k=0; k<10; k++)
        {
            items.push({
                value:k,
                display:"Hello World"
            })
        }

    }


}

标签: nativescriptnativescript-angular

解决方案


尝试这个..

您正在分配不是 ValueList bype 的数组,其中 items 变量是。所以我想这就是导致问题的原因。

考虑下面提到的代码,如Documentation.

   public items: ValueList<string>;

   constructor() {
      let valueItems = [];

      for(var k=0; k<10; k++) {
         valueItems.push({
             value:k,
             display:"Hello World"
         });
      }

     this.items = new ValueList<string>(valueItems);

}

我认为您在模板代码中有错字..

<StackLayout orientation="vertical">
    <DropDown [items]="items"></DropDown>   
</StackLayout>

希望这可以帮助.. :)


推荐阅读