角度ng重复列表值拆分

时间:2017-01-07 20:14:36

标签: javascript angularjs angularjs-ng-repeat

我将以下数据存储在localstorage中,我想在html页面中检索搜索历史记录中的这些值(假设搜索历史是一个列表)。

hotelSearchCriteria = {
        destination : location,
        datesInfo:{
            checkInDate : '2017/05/22',
            checkOutDate: '2017/05/30'
        }
}
localStorage.setItem("hotelSearchCriteria", JSON.stringify(hotelSearchCriteria));

var storedInfoArray = JSON.parse(localStorage.getItem('hotelSearchCriteria'));
if(storedInfoArray != null){
    $scope.storedInfoArrayAngular = storedInfoArray;
}

我想使用ng-repeat检索这些值,我需要按如下方式拆分checkInDate和checkOutDate“05/22(Mon) - 05/30(Tue)”         我能够成功地将数据存储在localStorage中作为列表,但我在检索这些值列表时遇到问题。如何在ng-repeat中分割日期?

<li ng-repeat="storedInfo in storedInfoArrayAngular">
    <p>{{storedInfo.destination}}</p> 
    <span>{{storedInfo.checkInDate}}</span> - <span>{{storedInfo.checkOutDate}}</span>
</li>

预期结果

搜索记录

新加坡

05/22(星期一) - 05/30(星期二)

东京

05/22(星期一) - 05/30(星期二)

任何人都可以帮助我吗?提前致谢

1 个答案:

答案 0 :(得分:2)

看起来checkInDatecheckOutDatestoredInfo.datesInfo的属性,所以在引用它时应该使用完整的对象路径:

<li ng-repeat="storedInfo in storedInfoArrayAngular">
    <p>{{storedInfo.destination}}</p> 
    <span>{{storedInfo.datesInfo.checkInDate}}</span> - <span>{{storedInfo.datesInfo.checkOutDate}}</span>
</li>

要将日期格式设置为 05/22(星期一),您可以使用date filter,如下所示:

{{ storedInfo.datesInfo.checkInDate | date: "MM/dd (EEE)" }}