简体   繁体   English

如何使用角度js访问此json数据

[英]How can I access this json data using angular js

Im trying to access this json data using ng-repeat in angular. 我试图使用ng-repeat in angular访问这个json数据。 But I data does not come to the view. 但我的数据并未出现在观点中。

<div class="panel-body" ng-repeat="product in Brands track by $index">

                        <label>{{product.ID}}</label>
                        <label style="margin-right: 10px;">{{product.Name}}</label>
                        <input type="checkbox" ng-model="formData.Selected" ng-true-value='"Y"'
                               ng-false-value='"N"' value="{{product.Name}}" style="margin-right: 10px;" cd-true-value="'{{product.ID}}'" cd-false-value="'None'" />

This is a part of json data 这是json数据的一部分

Object {SelectFromDate: Thu Apr 07 2016 00:00:00 GMT+0530 , ToDate: Fri Apr 15 2016 00:00:00 GMT+0530 , Selected: "1"}
    {"data":[{"ID":1,"BrandID":1,"ProductID":1,"Name":"***","Created":"****"},{"ID":2,"BrandID":2,"ProductID":1,"Name":"***","Created":"****"},{"ID":3,"BrandID":3,"ProductID":1,"Name":"***","Created":"****"},{"ID":4,"BrandID":4,"ProductID":1,"Name":"***","Created":"****""},    {"ID":5,"BrandID":5,"ProductID":1,"Name":"***","Created":"****"},

this is the controller 这是控制器

$scope.submit = function() {
        console.log($scope.formData);


            angularService.PostAngularFormData($scope.formData).then(function (response) {
                $scope.Brands = JSON.stringify(response);
                console.log($scope.Brands);

            });

Use this 用这个

$scope.allResponse = JSON.parse(response);
$scope.brands = $scope.allResponse.data;
console.log($scope.brands);

or use 或使用

$scope.brands = angular.fromJson(response.data);
console.log($scope.brands);

Modify controller 修改控制器

angularService.PostAngularFormData($scope.formData).then(function (response) {
        $scope.Brands = response.data; 
        console.log($scope.Brands);

    });

Try it and give console out put 尝试并给出控制台

Modify controller 修改控制器

// I assume you result array 
var array = {"data":[{"ID":1,"BrandID":1,"ProductID":1,"Name":"RI","Created":"2016-04-11T23:‌​19:03.463"},
                 {"ID":2,"BrandID":2,"ProductID":1,"Name":"BLE","Created":"2016-04-11T‌​23:19:03.48"} ]};

$scope.brands = array.data;

Inside view 内部视图

<div ng-repeat="brand in brands">
    {{brand}}
</div>

my View out put 我的观点出来了

{"ID":1,"BrandID":1,"ProductID":1,"Name":"RI","Created":"2016-04-11T23:‌​19:03.463"}
{"ID":2,"BrandID":2,"ProductID":1,"Name":"BLE","Created":"2016-04-11T‌​23:19:03.48"}

Try it and solve your problem 尝试并解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM