【问题标题】:Parse JSON using AngularJS使用 AngularJS 解析 JSON
【发布时间】:2014-11-16 11:15:12
【问题描述】:

我有以下 JSON 数据,我想使用 AngularJS 解析它

{
    "count": 104,
    "entries": [
        [
            "74",
            "Aakash",
            "/images/brands/aakash.png"
        ],
        [
            "51",
            "Aashirvaad",
            "/images/brands/aashirvaad.png"
        ],
        [
            "42",
            "ACT II",
            "/images/brands/act-ii.png"
        ],
        [
            "47",
            "Amul",
            "/images/brands/amul.png"
        ],
        [
            "48",
            "Anik",
            "/images/brands/anik.png"
        ],
        [
            "52",
            "Annapurna",
            "/images/brands/annapurna.png"
        ],
        [
            "3",
            "Ariel",
            "/images/brands/ariel.png"
        ],
        [
            "6",
            "Auyr Herbal",
            "/images/brands/ayur-herbal.png"
        ],
        [
            "29",
            "Axe",
            "/images/brands/axe.png"
        ],
        [
            "20",
            "Bajaj",
            "/images/brands/bajaj.png"
        ],
        [
            "46",
            "Boost",
            "/images/brands/boost.png"
        ],
        [
            "76",
            "Britannia",
            "/images/brands/britannia.png"
        ]
    ]
}

我将使用此函数获取以上 JSON 数据:

function customersController($scope,$http) 
{
    $http.get("http://example.com/website/brands_JSON.php")
        .success(function(response) {$scope.names = response;});
}

并尝试使用以下方式显示它:

<div ng-app="" ng-controller="customersController"> 
    <table class='table table-bordered'>
        <caption>BRAND'S LIST</caption>
        <thead>
            <tr><th>#</th><th>Brand Name</th><th>ImagePath</th><th>Image</th></tr>
        </thead>
        <tr ng-repeat="x in names.entries">
            <td>{{ names.entries[0][0]}} </td>
            <td>{{ names.entries[0][1]}} </td>
            <td>{{ names.entries[0][2]}} </td>
            <td>{{ names.entries[0][3]}} </td>
        </tr>

    </table>
</div>

但是除了表头之外什么都没有显示。

谁能帮忙?

【问题讨论】:

    标签: javascript jquery json angularjs


    【解决方案1】:

    您应该使用 x[i] 来显示数据,因为 'ng-repeat="x in names.entries"':

    <div ng-app="" ng-controller="customersController">
    <table class='table table-bordered'>
        <caption>BRAND'S LIST</caption>
        <thead>
            <!-- your table head -->
        </thead>
        <tr ng-repeat="x in names.entries">
            <td>{{x[0]}} </td> 
            <td>{{x[1]}} </td>
            <td>{{x[2]}} </td> 
        </tr>
     </table> 
    </div>
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-28
    相关资源
    最近更新 更多