nativescript - 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"
})
}
}
}
解决方案
尝试这个..
您正在分配不是 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>
希望这可以帮助.. :)
推荐阅读
- pyspark - Pyspark - 在每个 ID 中,我希望根据行的位置分配权重
- c++ - C++ 将包含多态属性的类对象存储在堆栈中
- python - 如何将 csv 读入列表和字典
- typescript - 错误 TS2339:“文件上传”类型上不存在属性“_input”
- javascript - 无法访问响应数据对象
- mysql - Mysql Date Column:为什么有时使用索引键有时不使用?
- c# - 有没有办法在不截屏 C# 的情况下捕获屏幕像素的颜色?
- python - 如何设置副轴的主定位器
- javascript - 如何在JS中找到事件目标的父节点的索引?
- reactjs - 当我注销时,警告:无法对未安装的组件执行 React 状态更新