Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 财产';键';不存在于类型';任何[]和#x27;_Javascript_Ionic Framework - Fatal编程技术网

Javascript 财产';键';不存在于类型';任何[]和#x27;

Javascript 财产';键';不存在于类型';任何[]和#x27;,javascript,ionic-framework,Javascript,Ionic Framework,我不明白为什么会出现这个错误: ==>类型“any[]”上不存在属性“key” import { Component } from '@angular/core'; import { IonicPage, NavController, NavParams } from 'ionic-angular'; @IonicPage() @Component({ selector: 'page-tourist', templateUrl: 'tourist.html', }) export cl

我不明白为什么会出现这个错误: ==>类型“any[]”上不存在属性“key”

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';

@IonicPage()
@Component({
  selector: 'page-tourist',
  templateUrl: 'tourist.html',
})
export class TouristPage {

    tourist : Array<any> ;
    key: any;

    constructor(
        public navCtrl: NavController,
        public navParams: NavParams,
    ) {
        this.tourist = navParams.get("tourist");
        this.key = this.tourist.key;
    }
从'@angular/core'导入{Component};
从“离子角度”导入{IonicPage,NavController,NavParams};
@IonicPage()
@组成部分({
选择器:“页面浏览者”,
templateUrl:'tourism.html',
})
出口级旅游{
游客:阵列;
键:任意;
建造师(
公共navCtrl:NavController,
公共导航参数:导航参数,
) {
this.tourism=navParams.get(“tourism”);
this.key=this.tourism.key;
}
any[]
表示“包含任何类型值的数组”

数组有一个属性(虽然它是一个函数,所以可能不是您想要的),但没有
key
属性

您可能希望从数组中获取值并查看它们的
属性

考虑或出于此目的。

您已将“游客”声明为数组,您在评论中说,当您执行console.log时,它返回
{available:true,gp:58,lat:4…,key:12345}
,知道我假定游客是任何类型的对象


如果您将
touriser:Array;
更改为
touriser:any;
可能会起作用。

touriser
是一个数组典型的数组没有
。key
属性。key是一个值,而不是数组的键,“touriser”中的“name”值也会有同样的问题数组。我该怎么处理?你是说,我应该先访问“旅游者”数组?@Matthieu-我是说你可能想要
tourism[0]。key
tourism[1]。key
tourism[2]。key
等等……但这是一个推测。我的数组在控制台上是“tourism”。log它看起来像:{available:true,gp:58,lat:4…,key:12345}我只有一行…@Matthieu-那么你说
tourism:Array