Nativescript 财产';推动';在ValueList下拉列表中的类型上不存在

Nativescript 财产';推动';在ValueList下拉列表中的类型上不存在,nativescript,nativescript-angular,Nativescript,Nativescript Angular,我正在使用本机脚本开发android和ios应用程序。我在我的应用程序中使用了nativescript下拉插件。我使用valuelist数组在下拉列表中绘制值。但是值列表返回错误,比如“属性‘push’在值列表下拉列表中的类型上不存在”。我不知道这个问题是如何产生的。帮我解决这个问题 我的示例代码: 我的Html: <StackLayout orientation="vertical"> <DropDown [items>="items"></Drop

我正在使用本机脚本开发android和ios应用程序。我在我的应用程序中使用了nativescript下拉插件。我使用valuelist数组在下拉列表中绘制值。但是值列表返回错误,比如“属性‘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"
            })
        }

    }


}
从“@angular/core”导入{Component};
从“nativescript下拉列表”导入{ValueList};
@组成部分({
选择器:“我的应用程序”,
templateUrl:“app.component.html”,
})
导出类AppComponent{
公共项目:价值清单;
构造函数(){
此参数为.items=[];
对于(var k=0;k试试这个

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

考虑下面的代码,如中所述

公共项目:价值清单;
构造函数(){
设valueItems=[];

对于(var k=0;kCan您可以共享一些代码吗?这是一个TypeScript编译时错误吗?Hai manoj我已经共享了我的代码好的,谢谢,它正在工作。但是splice属性和length属性也显示了一个错误,如“属性”splice或length“在ValueList下拉列表中的类型上不存在”。我不明白为什么会发生此错误?您可能需要在
valueItems
中为
value
属性添加字符串,而不是数字…我在项目中添加了字符串值,但它没有工作。实际上,根据文档,我们需要为自定义对象条目添加长度..我到目前为止还没有使用此项..因此我对其理解有限我想,你可以通过阅读文档来做这件事。考虑一下投票,并把它标记为答案,如果它能帮助你从最初的问题中解脱出来。
   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>