cordova - 带背景色
问题描述
我正在寻找一种使用 *ngFor 生成列表的方法,其中每个生成的列表将具有 3 种可能的背景颜色中的 1 种。我的 .ts 文件中有以下内容:
this.items = [
{id:'00001', status:'pending', title: 'hi1', description: 'test1'},
{id:'00002', status:'pending', title: 'hi2', description: 'test2'},
{id:'00003', status:'pending', title: 'hi3', description: 'test3'}
];
我的 .html 文件中有这个:
<ion-content>
<ion-list>
<ion-item *ngFor="let item of items" (click)="viewItem(item)" ng-style="{'background-color': {{item.status}}}">{{item.title}}</ion-item>
</ion-list>
</ion-content>
我在 variables.svss 文件中添加了 $colors 。该文件现在如下所示:
$colors: (
primary: #488aff,
secondary: #32db64,
danger: #f53d3d,
light: #f4f4f4,
dark: #222,
pending: #FFFF99,
complete: #9966ff,
overdue: #ff0000
);
所以,我的目标是让 ion-item 使用它的 this.status 来确定正确的背景颜色。当我运行我的应用程序时,这是生成的 html:
<ion-item class="item item-block item-ios" ng-style="{'background-color': item.status}">
显然,我不打算将“item.status”作为背景颜色,我希望使用#FFFF99。
非常感谢任何建议或意见。
解决方案
为什么不为可能的状态添加一些 (S)CSS 类,如下所示:
.pending {
background-color: #FFFF99;
}
.complete {
background-color: #9966ff;
}
.overdue {
background-color: #ff0000;
}
然后根据状态动态设置项目的类,如下所示:
<ion-item *ngFor="let item of items" [class]="item.status">{{item.title}}</ion-item>
推荐阅读
- animation - SVG textPath动画在页面上滚动多次
- pandas - 如何在熊猫中旋转数据框条形图?
- java - 更改日期格式
- powershell - Powershell返回布尔值失败
- oop - Lua继承和方法
- javascript - 从 JS 切换到 TS 时类型错误上不存在属性
- css - 为什么我的图像不显示,鉴于我的动画也不能正常工作,我怎么能增加空间
- node.js - gcloud Nodejs http 500 error cannot find server.js in workspace [更详细的转贴]
- reactjs - 在 React 中获取 [object Object] 而不是 object
- quarkus - 如何使用连字符为 quarkus 属性设置环境变量?