【发布时间】:2017-10-24 16:22:35
【问题描述】:
我正在使用 Ionic 2 框架以及 Angular 2 和 Ts。
在我的 ts 文件中,我有一个变量,比如说“round”和一个对象“textblocks”
round:number;
textblocks=[{hello:'hi'},{hello:'there'},{hello:'john'},{hello:'doe'}];
'Round' 值在应用程序的生命周期内不断变化(0 到 3)。
然后在我的 html 文件中,我有一个列表:
<ul>
<li>{{textblocks[round].hello}}</li>
</ul>
我可以使用 ngFor 来显示与变量“round”中的数字一样多的“li”,每个都显示对应的 textblocks[round].hello 中的文本,使用视图时“round”增加?
round 为 1 时的示例
<ul>
<li>{{textblocks[0].hello}}</li>
<li>{{textblocks[1].hello}}</li>
</ul>
那是
- 你好
- 那里
round 为 3 时的示例
<ul>
<li>{{textblocks[0].hello}}</li>
<li>{{textblocks[1].hello}}</li>
<li>{{textblocks[2].hello}}</li>
<li>{{textblocks[3].hello}}</li>
</ul>
- 你好
- 那里
- 约翰
- 确实
【问题讨论】:
-
不。我以前找到了那个答案,但它没有考虑到“变量”问题。它解释了如何重复一个元素固定的次数(答案比 trichetriche 这里提供的要复杂得多)
标签: cordova angular ionic-framework ngfor