在离子 2 中打印自定义对象



我的应用程序中有一个类 SL-Leg.It 它有一些变量可以保存这些值。当我打印此类的对象时,正在打印[对象对象]但是当我尝试通过 myObject.line 访问类的值时,例如,会出现一个未定义的错误不是对象(评估 self.context.$implicit.line

leglist 是数组,它保存来自类 SL'Leg 的对象。

<ion-header>
  <ion-navbar>
    <ion-title>showTripInfo</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>
<ion-content class="show-trips">
    <ion-list>
      <ion-item-group *ngFor="let leg of legList" (click) = "showTripInfo(tp)">
        <ion-card>
          <table style="width:100%">
<tr>
  <div class="page-show-trips.card-title">
    <th item-width="100%">{{leg}} >> {{leg.line}}</th>
  </div>
</tr>
<tr>
  <div class="page-show-trips.card-subtitle">
    <th item-width="100%">{{leg}} >> {{leg}}</th>
  </div>
</tr>
</table>

<div ng-repeat="(key, value) in tp.LegList" > {{key}} {{value}} </div>
</ion-card>
</ion-item-group>
</ion-list>
</ion-content>
</ion-content>

SL-Leg在这里我

mport { Component } from '@angular/core';
import { NavController, NavParams } from 'ionic-angular';
import { Address } from './sl-Address';
/*
  Generated class for the SlTripClass page.
  See http://ionicframework.com/docs/v2/components/#navigation for more info on
  Ionic pages and navigation.
*/
@Component({
  selector: 'page-sl-legs',
  //templateUrl: 'sl-trip-class.html'
})
export class Leg {
    // public from_time: String;
    public legIndex: Number;
    public enabled_TransportType: Boolean; // Default True
    public enabled_LineNumber: Boolean; // Default true
    public showHideLeg: Boolean; // Default true means show all legs
    public filterLine: Boolean;
    public filterDepartures: Boolean;
    // ...:Common publiciables available in Travel /Walk
    public journeyType : String;
// available via LegDetail
    public origin: Address;
    public destination: Address;
    public name: String;
    public type: String;
    public idx: String;
    public geomRef: String;
    public legImageName: String;
    //-- Only found in --------Walk
    public dist: String;
    public hide: String;
    //-- Only found in --------Travel
    public dir: String;
    public line: String;
    public journeyDetailRef: String;
    public rtu_Message_Flag: Boolean;
    public rtu_Message: String;
//  constructor(public tripObjectFromSl: any,public navCtrl: NavController, public navParams: NavParams) {
    constructor() {
    this.legIndex = 0;
    this.enabled_TransportType= true; // Default True
    this.enabled_LineNumber= true;
    this.showHideLeg= true;
    this.filterLine= false;
    this.filterDepartures;
    this.journeyType= String();;
    this.origin= new Address();
    this.destination= new Address();
    this.name= String();
    this.type= String();
    this.idx= String();
    this.geomRef= String();
    this.legImageName= String();
    this.dist= String();
    this.hide= String();
    //-- Only found in --------Travel
    this.dir= String();
    this.line= String();
    this.journeyDetailRef= String();
    this.rtu_Message_Flag= true;
    this.rtu_Message= String();
  }
  ionViewDidLoad() {
    console.log('ionViewDidLoad SlTripClassPage');
  }
}
数组

LegList中的第一个对象是nullundefined。你可以只放一个空检查

{{leg?.line}}

此外,legIndex值从 1 开始。我想您正在插入 for 循环起始索引 1。

相关内容

  • 没有找到相关文章

最新更新