【发布时间】:2014-02-17 18:52:43
【问题描述】:
您如何找到正确的方法来进行这种比较?我尝试了各种方法。我什至使用了 id,但他们没有回应。如果我做这个“gumboots”字符串检查,它确实有效。 “gumboots”只是存在于表格某处的产品名称的字符串值。这就是我知道我根本不需要 PHP 的原因,尽管在下面的索引视图中的 PHP 中显示了表格。任何想法?我会很感激。
这是javascript
$('#example tbody tr td').each(function()
{
var p_no_in_stock = parseInt(document.getElementById('p_no_in_stock')).value;
var p_reorder_quantity = parseInt(document.getElementById('p_reorder_quantity')).value;
//if ($product['Product']['p_no_in_stock'].val() < $product['Product']['p_reorder_quantity'].val())
if ($(this).text() == "gumboots")
//if ($(this).p_no_in_stock < $(this).p_reorder_quantity)
{
//$("#row_" +" td").effect("highlight", {}, 1500);
$(this).parent().attr('style','background:red');
$(this).parent().css('font-weight','bold');
}
});
这是一个名为 Products.index 的视图中的应用程序
<div class="active">
<h2><?php echo __('Products'); ?></h2>
<table cellpadding="0" cellspacing="0" class="table table-striped table-bordered" id ="example">
<tr>
<th><?php echo $this->Paginator->sort('p_name', 'Name'); ?></th>
<th><?php echo $this->Paginator->sort('category_name', 'Category'); ?></th>
<th><?php echo $this->Paginator->sort('p_no_in_stock','No. in Stock'); ?></th>
<th><?php echo $this->Paginator->sort('p_reorder_quantity', 'Re-order Quantity'); ?></th>
<th class="actions"><?php echo __('Actions'); ?></th>
</tr>
<tbody>
<?php foreach ($products as $product): ?>
<tr>
<td><?php echo h($product['Product']['p_name']); ?></td>
<td> <?php echo $this->Html->link($product['Category']['category_name'],
array('controller' => 'categories', 'action' => 'view', $product['Category']['id'])); ?>
</td>
<td id = "p_no_in_stock" type ="number" ><?php echo h($product['Product']['p_no_in_stock']); ?> </td>
<td id ="p_reorder_quantity" type ="number" ><?php echo h($product['Product']['p_reorder_quantity']); ?> </td>
<td class="actions">
<?php echo $this->Html->link(__('View'), array('action' => 'view', $product['Product']['id']), array('class' => 'btn btn-mini')); ?>
<?php echo $this->Html->link(__('Edit'), array('action' => 'edit', $product['Product']['id']), array('class' => 'btn btn-mini')); ?>
<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $product['Product']['id']), array('class' => 'btn btn-mini'), __('Are you sure you want to delete # %s?', $product['Product']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
提前致谢。
解决的问题
删除类型编号
编辑tr标签为
<tr class ="item-row"> after foreach part.
【问题讨论】:
-
让我看看我是否明白你在这里想要做什么。所以你正在渲染一个表,并且你想在其中搜索一个特定的字符串。如果您在任何行中找到它,您希望突出显示该行以指示匹配。对吗?
-
不,我想突出显示产品的行,其中一个名为“p_no_in_stock”的数字的比较小于“p_reorder_quantity”。每个产品都有这些属性。我只是想表明简单的字符串条件与突出显示功能一起使用,并且我希望比较可以使用它。
-
嗯,好的,知道了。因此,与需要重新订购的产品相比,您希望突出显示库存产品较少的行。我会在下面发布一些内容供您尝试,请稍等。
标签: javascript php css cakephp highlighting