I just want to know how to nicely display my sessionStorage JSON data in my html
我只是想知道如何在我的html中很好地显示我的sessionStorage JSON数据
My datas are well stored in my sessionStorage like that :
我的数据存储在我的sessionStorage中,就像那样:
Bellow is my Controller
贝娄是我的财务总监
app.controller('optionController', ['$scope', function($scope) {
var myObject = JSON.parse(sessionStorage.getItem("flight"));
$scope.getItemSS = myObject;
};
}])
Bellow is how I try to display them
贝娄是我试图展示它们的方式
<section ng-controller="optionController">
<ul ng-repeat="data in getItemSS">
<li>From <strong>{{ data.departure }}</strong></li>
<li>To <strong>{{ data.destination }}</strong></li>
<li>Departure at <strong>{{ data.time.departure }}h</strong></li>
<li>Arrival at <strong>{{ data.time.destination }}h</strong></li>
<li>For <strong>{{ data.firstName }} {{ data.lastName }}</strong></li>
<li>Only for <strong>{{ data.price }}€</strong></li>
<p>Congratulation, you confirmed your flight! An email has been sent to your email <strong>{{ data.email }}</strong></p>
</ul>
</section>
I am not able to display my data. Any idea ?
我无法显示我的数据。任何想法 ?
1 个解决方案
#1
2
Your code is implying that the session storage item by key flight
is an array - it is not. It is an object whose top (and only) key is called flights
that points to an array.
您的代码暗示按键飞行的会话存储项是一个数组 - 事实并非如此。它是一个对象,其顶部(和唯一)键称为指向数组的飞行。
This is the code you want to use:
这是您要使用的代码:
var myObject = JSON.parse(sessionStorage.getItem("flight"));
$scope.getItemSS = myObject.flights;
instead of
代替
var myObject = JSON.parse(sessionStorage.getItem("flight"));
$scope.getItemSS = myObject;
Alternatively you could use the same JS and change your view to be:
或者,您可以使用相同的JS并将视图更改为:
<ul ng-repeat="data in getItemSS.flights">
#1
2
Your code is implying that the session storage item by key flight
is an array - it is not. It is an object whose top (and only) key is called flights
that points to an array.
您的代码暗示按键飞行的会话存储项是一个数组 - 事实并非如此。它是一个对象,其顶部(和唯一)键称为指向数组的飞行。
This is the code you want to use:
这是您要使用的代码:
var myObject = JSON.parse(sessionStorage.getItem("flight"));
$scope.getItemSS = myObject.flights;
instead of
代替
var myObject = JSON.parse(sessionStorage.getItem("flight"));
$scope.getItemSS = myObject;
Alternatively you could use the same JS and change your view to be:
或者,您可以使用相同的JS并将视图更改为:
<ul ng-repeat="data in getItemSS.flights">