javascript - 动态地将类添加到字符串中的单词Angular
问题描述
如果匹配某些条件,我想为字符串中的单词添加一个类
Your Bulk Creation: 8312e9, has Completed With Error. Please navigate to Outgoing Invoices> Create> Bulk History to view results.
我有这个字符串,现在如果字符串包含状态,CompletedWithError
那么在上面的文本中我必须在单词中添加一个类Completed With Error
元数据如下:
dateCreated: "2021-08-06T06:26:16.621Z"
isError: false
isRead: false
message: "Your Bulk Creation: 8312e9, has Completed With Error. Please navigate to Outgoing Invoices> Create> Bulk History to view results."
metaData: {
recordType: "Invoice",
recordId: "610942b92c463500128312e9",
recordStatus: "CompletedWithError"
}
该字符串是动态的,也可以包含任何其他状态,有什么办法吗?
解决方案
您可以检查这些字符串是否存在,如果它们确实存在,然后将其作为布尔值返回,如果其为真,然后将其添加到消息中,您可以重新制定响应对象 - 我尽可能简单地保留它。包含区分大小写。
if(message){
const contains = message.includes('Completed With Error')
if(contains){
return message + 'Has Completed With Errors'
}
}
推荐阅读
- hyperledger-fabric - lib/script.js 中的 TP 与 composer-client 中的assetRegistry 更新资产?
- perl - Perl cgi 确实在 apache2 中工作
- python - 没有名称“路径”问题,无法在 django、lubuntu 中启动项目
- java - 无效的签名文件 Maven
- ruby-on-rails - Ion DateTime 还将 DateTime 发送为 UTC (Z)
- powershell - 如何优化 findstr 的排序值
- python - 熊猫重新索引多索引并按第二个索引移动值
- python - 使用 Selenium Scraper (Python) 时消除 % 符号
- android - 插件权限 xamarin.forms
- php - Laravel 模型未绑定在控制器方法中