Nis*_*sin 1 javascript angularjs angularjs-directive ng-repeat
我有一张桌子和许多<td>s,<tr> </tr>我首先使用的是ng-repeat
<tr ng-repeat="receipt in $data">
<td data-title="voucher number">
<span>{{receipt.voucher_no}}</span>
</td>
<td data-title="voucher date" sortable="'voucher_date'" filter="{'voucher_date': 'text' }">
<span>{{receipt.voucher_date}}</span>
</td>
<td data-title="voucher Amount">
<span>{{receipt.voucher_amount}}</span>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
我也有json数据
{
"data": [
{
"voucher_no": "2",
"voucher_amount": "100",
"voucher_date": "2014-05-04",
},
{
"voucher_no": "3",
"voucher_amount": "1000000",
"voucher_date": "2014-02-05",
},
{
"voucher_no": "4",
"voucher_amount": "50000",
"voucher_date": "2014-02-05",
},
.
.
.
.
{
"total": 1360100
}
]
}
please note that for final data there is only one field 'total'.
Run Code Online (Sandbox Code Playgroud)
所以对于我要打印3 <td>秒的所有行,除了最后一行.
<tr ng-repeat="receipt in $data | filter:{voucher_date: '2014-05-04'}">
<!-- Voucher No -->
<td ng-if="!$last"
data-title="voucher number">
<span>{{receipt.voucher_no}}</span>
</td>
<!-- Voucher Date -->
<td ng-if="!$last"
data-title="voucher date">
<span>{{receipt.voucher_date}}</span>
</td>
<!-- Voucher Amount -->
<td ng-if="!$last"
data-title="voucher Amount">
<span>{{receipt.voucher_amount}}</span>
</td>
<!-- Total Column -->
<td ng-if="$last"
colspan="3"
data-title="Total">
<span>{{receipt.total}}</span>
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
上述过滤器仅显示日期等于指定日期的记录.
如果要显示两个日期之间的所有记录,则需要将函数指定为过滤器:| filter:filter_between_date在控制器中,您必须创建该函数:
$scope.from_date = '2014-05-04'; // 04 May
$scope.to_date = '2014-05-10'; // 10 May
$scope.filter_between_date = function(item) {
var item_date = new Date(item.voucher_date).getTime();
if(item_date >= (new Date($scope.from_date).getTime()) &&
item_date <= (new Date($scope.to_date).getTime()) {
return true;
}
return false;
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5584 次 |
| 最近记录: |