【发布时间】:2015-10-01 08:39:04
【问题描述】:
我使用Bootstrap Table 远程加载我的数据data-url="data.json"。所以我的桌子:
<table id="mytable" class="table table-hover" data-url="data.json" data-toggle="table" id="table-pagination" data-pagination="true">
<thead>
<tr>
<th data-field="id" data-align="center">id</th>
<th data-field="type" data-align="center">type</th>
<th data-field="name" data-align="center">name</th>
<th data-field="product" data-align="center">product</th>
<th data-field="use" data-align="center">use</th>
<th data-field="quantity" data-sortable="true">quantity</th>
</tr>
</thead>
</table>
最后一列只有数字(没有任何其他字符)。 data.json 是这样的:
[
{
"id": 120,
"type": "type1",
"name": "name 1",
"product": "250304-01",
"use": "use 1",
"quantity": 10000
},
{
"id": 121,
"type": "type2",
"description": "name 2",
"product": "250124-01",
"cutter": "use 1",
"quantity": 80
}
]
我想检查,当最后一列中的值小于 100 时,将在该 tr 中添加一个类。我搜索了一下,发现可以使用filter 完成。所以,我编码:
$('tbody tr').filter( function(){
return $('td:last', this).text() < 100;
}).addClass('warning');
我将上面的内容原封不动地保存到文件addWarning.js 中,并将其放在我页面底部的所有其他scripts 的末尾。
<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
<script src="assets/js/bootstrap-table.js"></script>
<script src="assets/js/bootstrap-table-el-GR.js"></script>
<script src="assets/js/addWarning.js"></script>
但它不起作用..我错过了什么?
【问题讨论】:
-
您是否尝试过调试它以查看您的问题发生在哪里(即它是选择器,还是在过滤器功能中)?
-
@PranavCBalan 添加后如何进行检查?
-
addWarning.js或addWarnings.js?或者这只是你的问题中的一个错字? -
@TusharKhatiwada 我已编辑,感谢您的注意
标签: jquery twitter-bootstrap-3 addclass bootstrap-table