单击按钮不会在单击时激活

时间:2018-05-26 08:32:24

标签: angularjs ionic3

这是我的打字稿文件:

new sap.m.StandardListItem({
                      type: "Active",
                      title: "Sort by date",
                      press:function(oEvent){
                        var oSorter = new sap.ui.model.Sorter("CRDT",false,false);
                        var oList = _this.getView().byId("commentListView");
                        var oBinding = oList.getBinding("items");
                        oSorter.fnCompare = function(firstParam,secondParam) {
                            var firstDate = Date.parse(firstParam).getTime();
                            var secondDate = Date.parse(secondParam).getTime();
                            return firstDate === secondDate ? 0 : (firstDate < secondDate ? -1 : 1);
                        };
                        oBinding.sort(oSorter);
                      }
                    }).addStyleClass("sapUiNoMargin sapUiNoContentPadding"),

及其html:

import { Component, ViewChild } from '@angular/core';
import { NavController, NavParams, App, ViewController, Slides, Platform, LoadingController } from 'ionic-angular';
import { CategoriesPage } from '../categories/categories';
import { StatesProvider } from '../../providers/states/states';

@Component({
  selector: 'page-sell',
  templateUrl: 'sell.html'
})
export class SellPage {
  @ViewChild('mySlider') slider: Slides;
  tempStates: any;
  states = [];
  sellsegments: number;
  cities: any;
  patCat: string;
  ids = [];
  allCitiesLoadingController: any;

  constructor(public viewCtrl: ViewController, public appCtrl: App, public platform: Platform,
    public navCtrl: NavController, public stateProvide: StatesProvider,
    private loadingController: LoadingController, public navParams: NavParams) {
  }

  ionViewDidLoad() {
    this.patCat = this.navParams.get('patcat');
    this.getStates();
  }

  ionViewDidEnter() {
    this.getCities();
  }

  loader() {
    this.allCitiesLoadingController = this.loadingController.create({
      spinner: 'hide',
      content: `
      <div class="cssload-loader">
        <div class="cssload-inner cssload-one"></div>
        <div class="cssload-inner cssload-two"></div>
        <div class="cssload-inner cssload-three"></div>
      </div>`
    });
  }

  onSegmentChanged(segmentButton) {
    const selectedIndex = this.states.findIndex((slide) => {
      return slide.id === segmentButton.value;
    });
    this.slider.slideTo(selectedIndex);
    this.getCities();
  }

  onSlideChanged(slider) {
    const currentSlide = this.states[slider.getActiveIndex()];
    this.sellsegments = currentSlide.id;
  }

  getStates() {
    this.stateProvide.getStates()
      .then(data => {
        this.tempStates = data;
        if (this.patCat === 'tourism') {
          let countArr = Object.keys(this.tempStates).map(key => this.tempStates[key]).map(x => x.tourismCount);
          let j = 0;
          for (let i in countArr) {
            if (countArr[i] > 0) {
              this.states[j] = this.tempStates[i];
              j = j + 1;
            }
          }
          this.sellsegments = this.states[0].id;
        } else if (this.patCat === 'rent') {
          let countArr = Object.keys(this.tempStates).map(key => this.tempStates[key]).map(x => x.estateRentCount);
          let j = 0;
          for (let i in countArr) {
            if (countArr[i] > 0) {
              this.states[j] = this.tempStates[i];
              j = j + 1;
            }
          }
          this.sellsegments = this.states[0].id;
        } else if (this.patCat === 'buy') {
          let countArr = Object.keys(this.tempStates).map(key => this.tempStates[key]).map(x => x.estateSaleCount);
          let j = 0;
          for (let i in countArr) {
            if (countArr[i] > 0) {
              this.states[j] = this.tempStates[i];
              j = j + 1;
            }
          }
          this.sellsegments = this.states[0].id;
        }
      });
  }

  getCities() {
    this.cities = null;
    if (typeof this.ids[this.sellsegments] !== "undefined") {
      this.cities = this.ids[this.sellsegments];
    } else {
      this.loader();
      this.allCitiesLoadingController.present().then(() => {
        this.stateProvide.getCitiesPro(this.sellsegments)
          .then((data) => {
            this.allCitiesLoadingController.dismiss();
            this.cities = data;
            this.ids[this.sellsegments] = this.cities;
          });
      });
    }
  }
}
当我滑动时,

幻灯片会发生变化。但是当我点击细分按钮时它不起作用。虽然以前工作过。当我改变我的getStates()函数时,问题就开始了。它只是应该获取API并将其存储在状态变量中。但我已经改变了一点,只根据上一页中点击的按钮显示适当的数据。所以我不明白为什么它不再起作用了。

1 个答案:

答案 0 :(得分:0)

似乎问题在于我将我的API存储在一个数组中: states = []; 所以我改变了我的代码如下,它的工作原理: 在构造函数之上我定义了我的变量:

  tempStates: any;
  tempState = [];
  states: any;

我改变了我的 getStates()功能,如下所示:

  getStates() {
    this.stateProvide.getStates()
      .then(data => {
        this.tempStates = data;
        if (this.patCat === 'tourism') {
          let countArr = Object.keys(this.tempStates).map(key => this.tempStates[key]).map(x => x.tourismCount);
          let j = 0;
          for (let i in countArr) {
            if (countArr[i] > 0) {
              this.tempState[j] = this.tempStates[i];
              j = j + 1;
            }
          }
          this.states = this.tempState;
          this.sellsegments = this.states[0].id;
        } else if (this.patCat === 'rent') {
          let countArr = Object.keys(this.tempStates).map(key => this.tempStates[key]).map(x => x.estateRentCount);
          let j = 0;
          for (let i in countArr) {
            if (countArr[i] > 0) {
              this.tempState[j] = this.tempStates[i];
              j = j + 1;
            }
          }
          this.states = this.tempState;
          this.sellsegments = this.states[0].id;
        } else if (this.patCat === 'buy') {
          let countArr = Object.keys(this.tempStates).map(key => this.tempStates[key]).map(x => x.estateSaleCount);
          let j = 0;
          for (let i in countArr) {
            if (countArr[i] > 0) {
              this.tempState[j] = this.tempStates[i];
              j = j + 1;
            }
          }
          this.states = this.tempState;
          this.sellsegments = this.states[0].id;
        }
      });
  }