javascript - 如何从存储在 localstorage 中的 json 字符串在 HTML 页面中显示 json 数据

标签 javascript angularjs json ng-repeat

我有以下格式从 laravel 返回的数据。我将其存储在本地存储中,供用户登录后使用。

我在前端使用angular,这就是我存储它的方式

$http.get($scope.url).success(function(redata){
    localStorage.setItem('session', JSON.stringify(redata));
    $scope.fulldata = JSON.parse(localStorage.getItem("session"));
});

这是json数据

{
"tweets":[
    {"id":"3","uid":"15","tweets":"Molly's first tweet"},
    {"id":"4","uid":"15","tweets":"molly again here, second tweet"},
    {"id":"5","uid":"15","tweets":"third tweet"}
   ],

"users":[
    {"id":"1","name":"rob","email":"rob@gmail.com","password":""},
    {"id":"2","name":"bob","email":"bob@gmail.com","password":""}
    ]
}

我可以使用 angular ng-repeat 显示 json

<p ng-repeat="data in fulldata">
    {{ data }}
</p>

但如果我只需要显示推文的内容,即推文的“tweets”字段,我该怎么做。

我试过了:-

<p ng-repeat="data in fulldata">
    {{ data.tweets.tweets }}
</p>

但这没有用。

谢谢

最佳答案

你必须在 tweets 数组上循环。

<p ng-repeat="data in fulldata.tweets">
    {{ data.tweets }}
</p>

关于javascript - 如何从存储在 localstorage 中的 json 字符串在 HTML 页面中显示 json 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35575746/

相关文章:

javascript - 基于边界动态设置初始 d3 缩放 - V4

javascript - AngularJS,使用 Ng-Repeat 和 Ng-Factory 显示 Json 数据

javascript - 如何让 JQuery 接受 JSON 回复?

c# - Unity5.3 Json如何使用unities new Json实用程序构造复杂的Json对象

c# - 存储过程结果集为 Json.NET 序列化程序的哪种 .NET 对象?

javascript - 在node js中查找最近创建的目录

javascript - 填充对象 Mongoose 的嵌套数组

javascript - 添加和覆盖现有插件中的功能

javascript - Angularjs 代码不工作

javascript - 从 Angular 调用节点