передать данные из переменной внутри функции в объявленную переменную - PullRequest
0 голосов
/ 11 января 2019

Я новичок в разработке, и мне нужна помощь в этом вопросе, я хочу, чтобы данные переменной регионовFiltered внутри функции getCountry () глобально, а не только внутри функции

      export class ShipmentManagementRegionPage {
      countryRegion;
      region;
      mainRegion;
      allRegions;
      filteredRegions;
      regionsFiltered;

      constructor(public navCtrl: NavController, public events: Events, public commerceFunction: CommerceFunction, public navParams: NavParams, public storage: Storage, ) {
      console.log(resgionsFiltered)
      }

      getCountry() {

          this.commerceFunction.Getadm1Shipping().subscribe(data => {
            this.mainRegion = data;
            console.log(this.mainRegion)
            this.storage.get("countryRegionList").then((data) => {
              this.countryRegion = data;
              console.log(this.countryRegion)
            })
            this.commerceFunction.GetGeoData_adm1OfCountry().subscribe(data => {
              this.region = data;

              for (let index = 0; index < this.mainRegion.length; index++) {
                let commonCountryRegion = this.countryRegion.find(x => x.CountryRegionCode == this.mainRegion[index].CountryRegionCodeID);
                this.mainRegion[index].CountryRegion = commonCountryRegion
                let commonAdm1 = this.region.find(x => x.cc_fips == this.mainRegion[index].CountryRegionCodeID);
                this.mainRegion[index].CountryRegion.adm1Shipping = commonAdm1
                let commonRegions = this.region.filter(x => x.cc_fips == this.mainRegion[index].CountryRegionCodeID);
                this.mainRegion[index].CountryRegion.geodata_adm1 = commonRegions
                this.regionsFiltered = commonRegions;
              }
              this.rowData = this.mainRegion

            });

          })

1 Ответ

0 голосов
/ 11 января 2019

Поскольку это машинопись, вам нужно объявить свойство regionFiltered для объекта окна:

declare global {
    interface Window { regionsFiltered: any; }
}

Тогда вы можете установить его:

for (let index = 0; index < this.mainRegion.length; index++) {
    ...
    this.regionsFiltered = commonRegions;
    window.regionsFiltered = this.regionsFiltered;
}

Тогда, где бы вы ни были, вы можете использовать window.regionsFiltered.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...