css - 用引号括起来的角函数返回变量显示为文本而不是渲染/使用不破坏 css 的不同方案
问题描述
我在我的 Angular 模板中有:
<ul>
{{ getRoundHtml(roundIndex) }}
</ul>
它在我的组件中调用一个函数:
getRoundHtml (indexRound){
this.roundHtmlStr = '';
console.log("INDEXR:", indexR);
for (let i = 0; i < this.entries/Math.pow(2,indexRound); i++){
this.roundHtmlStr = this.roundHtmlStr + `
<li class="spacer"> </li>\n
<li class="game game-top winner">Creighton <span>50</span></li>\n
<li class="game game-spacer"> </li>\n
<li class="game game-bottom">Harvard <span>40</span></li>\n
<li class="spacer"> </li>\n
`;
}
console.log("HTML:", this.roundHtmlStr.toString());
return(this.roundHtmlStr);
}
因为我不想添加另一个选择器或 *ngFor,因为它会由于在弹性框设置中添加另一个标签而破坏 CSS。
我曾尝试将嵌套选择器与 div、uls 等一起使用。它们不起作用,因为 css 中断。(再次,除非你能想出一个不同的解决方案)
解决方法: 1.如何获取:return(this.roundHtmlStr); 当它将它传递回插值 {{ getRoundHtml(roundIndex)}} 以不被包裹在“”中时;它基本上是包装返回值,而 html 实际上是显示文本而不是 html 渲染。
- 显示括号,其中 css 可以遵循该方案并为每一轮正确对齐匹配项,无论括号是 2、4、8、16、32、64 等大小。Angular 中的问题是 css不能遵循 flexbox 增长规则,因为选择器标签进入进程的中间并破坏了 css。
Round 1 Round 2 (small 4 team bracket)
Duke 79
-----------
| Duke 76
----------
| |
----------- |
UNC 72 | ND (Winner)
|-----------
|
Virginia 79 |
----------- |
| ND 91 |
----------
|
-----------
ND 72
解决方案
所以我想出了一个不同的解决方案。
我不得不扁平化嵌套选择器并将所有内容转储到一个包组件中,以消除嵌套选择器破坏 css。
我不得不将 HTML 的结构更改为:div
然后只匹配 ol 和 li 进行单场比赛,因此可以使用 for 循环重复,因为每一轮循环并且每一轮都有 2 的 n 次方 match/2 所以 32 人的第一轮有 16 场比赛,第二轮有8个等等。
推荐阅读
- java - 我可以在远程数据库中的 if 条件或 Java 中的 JSON 中使用条件运算符吗
- javascript - 如何正确使用 Javascript 来定位 Shiny 中的 gt 表行元素
- linux - 在 Linux 机器中找不到命令
- vb.net - 根据随机数计算每秒更改标签
- javascript - 如何用显示地图替换硬编码值?
- svelte - 防止在 Svelte 中双击 onclick
- python - 我无法在 matplotlib 中关闭我的绘图轴
- qt - 有没有办法让 QPushButton 背景透明,但添加图标?
- vhdl - 有人会帮我解决这个错误吗:std_logic_vector 不能有返回类型为 std_logic_vector 的操作数
- google-sheets - 向受保护工作表添加行的权限