2 回答
TA贡献1921条经验 获得超9个赞
<?php
foreach($customer as $customer_details)
{?>
<tr id="customer_details_<?=$customer_details['id']?>">
<?
foreach($dyncust_fields as $dyncust_field)
{
if($dyncust_field['add_to_listing']=='1')
{
$color = $customer_details[$dyncust_field['attribute_name']] == 'cname' ?'red':'green';
$search = array("{{color}}","{{data}}");
$replace = array($color,$customer_details[$dyncust_field['attribute_name']] );
$template = "<td style='color:{{color}};'>{{data}}</td>";
echo str_replace($search,$replace,$template);
}
}
?>
</tr>
<? }
?>
这$template是表格单元格的模板。$search数组中的值替换为$replace数组的值。这样,你只需要自定义模板,搜索和替换数组。例如,以下是您在评论部分提出的问题的答案。
$template = "<td> <a href='#list-corp-client' class='view-asset-inbox-model m-r-5 text-info' data-from='corporate' data-id='{{id}}' data-pk='1' data-toggle='modal'>{{title}}</a> </td>";
$search = array("{{id}}","{{title}}");
$replace = array($customer_details['id'], $asset_details['title']);
echo str_replace($search,$replace,$template);
TA贡献1846条经验 获得超7个赞
<?php
foreach($customer as $customer_details)
{?>
<tr id="customer_details_<?=$customer_details['id']?>">
<?
foreach($dyncust_fields as $dyncust_field)
{
if($dyncust_field['add_to_listing']=='1')
{
echo "<td style='".$customer_details[$dyncust_field['attribute_name']] == 'cname' ?'color:red':'color:green'."'>".$customer_details[$dyncust_field['attribute_name']]."</td>";
}
}
?>
</tr>
<? }
?>
或者您可以将类定义为内联样式或外部样式
<style>
.text-red{
color:red;
}
.text-green{
color:green;
}
</style>
<?php
foreach($customer as $customer_details)
{?>
<tr id="customer_details_<?=$customer_details['id']?>">
<?
foreach($dyncust_fields as $dyncust_field)
{
if($dyncust_field['add_to_listing']=='1')
{
$styleClass = $customer_details[$dyncust_field['attribute_name']] == 'cname' ?'text-red':'text-green'
echo "<td class='$styleClass'>".$customer_details[$dyncust_field['attribute_name']]."</td>";
}
}
?>
</tr>
<? }
?>
- 2 回答
- 0 关注
- 82 浏览
添加回答
举报