gpt4 book ai didi

javascript - Angular2/Javascript - 检索 for 循环内生成的变量的新值

转载 作者:行者123 更新时间:2023-12-02 14:41:13 24 4
gpt4 key购买 nike

我愿意检索在 for 循环内更新的变量的值并在范围之外访问它。

为此我有:Page.html

<div [options]="Pages">
<div *ngFor="#cat of category">
<div class="newCategory">The new category will appear here!</div>
<div>
</div>

Page.js

constructor(viewCtrl, http, navParams) {
this.viewCtrl = viewCtrl;
this.navParams = navParams;
this.http = http;
this.category = null;

this.http.get('https://website.com/api', { search }).subscribe(data => {
this.category = data.json().results;
});

//I want to print the new value of 'this.category' here
//e.g: console.log(this.category);

this.Pages = {
pagination: '.swiper-pagination',
slidesPerView: 1,
paginationClickable: true,
paginationBulletRender: function (index, className) {
//also I want to access it here
return '<span class="' + className + '">' + this.category[index+1] + '</span>';
}
}
}

我是否需要一个全局变量才能读取该变量的新值?或者我还需要别的东西吗?

最佳答案

最好的方法是存储 this.category 并将其在数组中循环,然后您将能够在 this.http 之外获取存储的值。获取()

关于javascript - Angular2/Javascript - 检索 for 循环内生成的变量的新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36988572/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com