如何在JSON数组angualrjs中显示单个值(how to display individual values within JSON array angualrjs)

编程入门 行业动态 更新时间:2024-10-25 00:35:45
如何在JSON数组angualrjs中显示单个值(how to display individual values within JSON array angualrjs)

我有一个名为(现在)0.json的json文件。 我想在json对象中显示某些数组作为单独的值(可能将它们显示为徽章)。

这是我的json:

[ { "id": "Chinwe Chukuwogu Roy WordPress Biography Website", "name": "Chinwe Roy Biography Website", "practices": ["UX", "HTML WireFraming", "Front-End Development", "Custom WordPress Theming"], "technology": ["WordPress", "HTML", "CSS", "JQuery", "TweenMax", "Inkscape", "Photoshop"], "time": "6 Weeks", "description": "A biography website celebrating the work of world reknowned Artist, Chinwe Chukwogu Roy", "images": "../assets/img/ux.svg", "header": "../assets/img/wordpress-project.svg", "behance": "https://www.behance.net/gallery/33173663/UI-Design-A-Website-Biography-Project" } ]

我在我的控制器中像这样调用json:

$http.get('app/resources/v1/projects/' + $routeParams.id + '.json').success(function (details) { $scope.details = details; });

HTML:

<div class="row" ng-controller="ProjectCtrl"> <ng-header class="header-directive">{{ detail.header }}</ng-header> <div class="container"> <div class="row"> <div class="col-md-12 work-parent" ng-repeat="detail in details"> <div class="work-child"> <h1>{{ detail.id }}</h1> <br> <p>{{ detail.description }}</p> <small><strong>technologies:</strong> {{ detail.technology }}</small> <small><strong>design practice:</strong> {{ detail.practices }}</small> <small><strong>turnaround:</strong> {{ detail.time }}</small> <ul class="social-icons"> <li class="behance"><a href="{{ detail.behance }}" target="_blank">behance</a></li> </ul> </div> </div> </div> </div> </div>

我遇到的问题是我无法将实践表现为个人价值观。 当我使用ng-repeat绑定detail.practices时,我只是在视图中得到一个完整的数组。

我如何在我的控制器中管理它?

I have a json file named (for now) 0.json. I want to display certain arrays within the json object as individual values (maybe display them as badges).

here is my json:

[ { "id": "Chinwe Chukuwogu Roy WordPress Biography Website", "name": "Chinwe Roy Biography Website", "practices": ["UX", "HTML WireFraming", "Front-End Development", "Custom WordPress Theming"], "technology": ["WordPress", "HTML", "CSS", "JQuery", "TweenMax", "Inkscape", "Photoshop"], "time": "6 Weeks", "description": "A biography website celebrating the work of world reknowned Artist, Chinwe Chukwogu Roy", "images": "../assets/img/ux.svg", "header": "../assets/img/wordpress-project.svg", "behance": "https://www.behance.net/gallery/33173663/UI-Design-A-Website-Biography-Project" } ]

I call the json like this within my controller:

$http.get('app/resources/v1/projects/' + $routeParams.id + '.json').success(function (details) { $scope.details = details; });

HTML:

<div class="row" ng-controller="ProjectCtrl"> <ng-header class="header-directive">{{ detail.header }}</ng-header> <div class="container"> <div class="row"> <div class="col-md-12 work-parent" ng-repeat="detail in details"> <div class="work-child"> <h1>{{ detail.id }}</h1> <br> <p>{{ detail.description }}</p> <small><strong>technologies:</strong> {{ detail.technology }}</small> <small><strong>design practice:</strong> {{ detail.practices }}</small> <small><strong>turnaround:</strong> {{ detail.time }}</small> <ul class="social-icons"> <li class="behance"><a href="{{ detail.behance }}" target="_blank">behance</a></li> </ul> </div> </div> </div> </div> </div>

The issue I am having is that I am unable to show e.g practices as individual values. I just get an complete array in the view when I bind detail.practices with an ng-repeat.

How would I manage this in my controller?

最满意答案

只需在主要内部嵌套另一个ng-repeat,所以沿着以下方向:

<small ng-repeat="practice in detail.practices"><strong>design practice:</strong> {{ practice }}</small>

或者,否则你希望它们出现。

Just nest another ng-repeat inside your main one, so along the lines of:

<small ng-repeat="practice in detail.practices"><strong>design practice:</strong> {{ practice }}</small>

Or however else you want them to appear.

更多推荐

本文发布于:2023-07-25 10:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1260038.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数组   如何在   JSON   angualrjs   array

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!