如何打印angularjs和HTML JSON数组对象数组 [英] how to print json array object array in angularjs and html

查看:252
本文介绍了如何打印angularjs和HTML JSON数组对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

angularjs控制器

controller('FaqCtrl', function($scope, $http)
{
$http.get("api/index.php/faq/getqusans")
.success(function (response) {
$scope.name = response.catname;

$scope.records = response.catname;

//$scope.question = response.records;

}); 
}).

HTML code

<div ng-controller="FaqCtrl" class="row">
<div class="" ng-repeat="y in name">
    <h3>{{ y.name }}</h3><br/>
    <div class="col-md-6" ng-repeat="x in records">

        <accordion close-others="true" >
            <accordion-group is-open="status1.open" ng-class="{'expanded': status1.open}" >
                <accordion-heading>{{ x.question }}</accordion-heading>
                {{ x.answer }}
            </accordion-group>

        </accordion>

    </div>
</div>


JSON响应

{
              "catname": [
                {
                  "name": "How do i 2",
                  "records": [
                    {
                      "question": "propose a new dish",
                      "answer": "Anim "
                    }
                  ]
                },
                {
                  "name": "How do i 3h",
                  "records": [
                    {
                      "question": "supply the dishes being demanded by heartyy",
                      "answer": "Anim"
                    },
                    {
                      "question": "sdsffd",
                      "answer": "vcvcvcvcvcv"
                    }
                  ]
                }
              ]
            }

我不上山寨的问题,并在HTML回答打印。只打印名字就像'我该怎么办2'和'我该怎么办2,但名字有quection提出了一个新菜和回答动画。

I am not gat the question and answer print in html. only print the name is like 'How do i 2' and 'How do i 2' but name have the quection 'propose a new dish' and answer 'Anim'.

推荐答案

我们需要编写的html如下

的jsfiddle

HTML code

HTML CODE

  <div ng-app ng-controller="LoginController">
 <div class="col-md-6" ng-repeat="x in parsedData">
<accordion close-others="true">
    <accordion-group is-open="status1.open" ng-class="{'expanded': status1.open}">
        <div>{{ x.name }}</div>
        <div ng-repeat="y in x.records">
            <accordion-heading><p>question is{{ y.question }}</p></accordion-heading>

JS code

JS CODE

function LoginController($scope) {
    var dataArr =[];
    var dataJson = {};
    $scope.data = {
              "catname": [
                {
                  "name": "How do i 2",
                  "records": [
                    {
                      "question": "propose a new dish",
                      "answer": "Anim "
                    },
                      {
                      "question": "propose a new dish",
                      "answer": "Anim "
                    },
                      {
                      "question": "propose a new dish",
                      "answer": "Anim "
                    }
                  ]
                },
                {
                  "name": "How do i 3h",
                  "records": [
                    {
                      "question": "supply the dishes being demanded by heartyy",
                      "answer": "Anim"
                    },
                    {
                      "question": "sdsffd",
                      "answer": "vcvcvcvcvcv"
                    }
                  ]
                }
              ]
            };

    $scope.parsedData = $scope.data.catname;
    console.log($scope.parsedData);
};

O / P:

How do i 2
question ispropose a new dish

answer is Anim

question ispropose a new dish

answer is Anim

question ispropose a new dish

answer is Anim

How do i 3h
question issupply the dishes being demanded by heartyy

answer is Anim

question issdsffd

answer is vcvcvcvcvcv

的jsfiddle

这篇关于如何打印angularjs和HTML JSON数组对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆