【问题标题】:Get specific value from Json array in angularJS with ng-repeat使用 ng-repeat 从 angularJS 中的 Json 数组获取特定值
【发布时间】:2016-03-07 10:16:36
【问题描述】:

部分代码

.controller('HomeCtrl', ['$scope', '$stateParams', 'lastactivities',
  function($scope, $stateParams, lastactivities) {
    var mytoken = sessionStorage.getItem('token');

    lastactivities.send(mytoken).then(function(activities) {
      var activitytab = activities.data;
      $scope.datab = activities.data;
    });
  }
])
<ul ng-repeat="item in datab">
  <li ng-repeat="value in item.date track by $index">{{value}}</li>
</ul>

JSON

{
  "erreur": "",
  "data": [{
    "date": "2016-03-04",
    "activities": [{
      "type": "bank",
      "icon": {
        "type": "lock-3",
        "color": "#000000"
      },
      "badge": {
        "text": "",
        "color": "#000000",
        "backgroundColor": "transparent"
      },
      "action": null,
      "title": "MOT DE PASSE MODIFIÉ",
      "description": ""
    }, {
      "type": "client",
      "icon": {
        "type": "document-1",
        "color": "#000000"
      },
      "badge": {
        "text": "1 400 €",
        "color": "#ffffff",
        "backgroundColor": "#97d42e"
      },
      "action": "925",
      "title": "FACTURE",
      "description": "nike - appli mobile"
    }, {
      "type": "client",
      "icon": {
        "type": "user-1",
        "color": "#000000"
      },
      "badge": {
        "text": "",
        "color": "#000000",
        "backgroundColor": "transparent"
      },
      "action": 925,
      "title": "NOUVEAU CLIENT",
      "description": "nike"
    }]
  }, {
    "date": "2016-03-03",
    "activities": [{
      "type": "bank",
      "icon": {
        "type": "lock-3",
        "color": "#000000"
      },
      "badge": {
        "text": "",
        "color": "#000000",
        "backgroundColor": "transparent"
      },
      "action": null,
      "title": "MOT DE PASSE MODIFIÉ",
      "description": ""
    }, {
      "type": "client",
      "icon": {
        "type": "document-1",
        "color": "#000000"
      },
      "badge": {
        "text": "643,44 €",
        "color": "#ffffff",
        "backgroundColor": "#f84c74"
      },
      "action": "719",
      "title": "FACTURE EN RETARD",
      "description": "Justine - Facture 2"
    }, {
      "type": "client",
      "icon": {
        "type": "document-1",
        "color": "#000000"
      },
      "badge": {
        "text": "400 €",
        "color": "#ffffff",
        "backgroundColor": "#f84c74"
      },
      "action": "719",
      "title": "FACTURE EN RETARD",
      "description": "Justine - Ma first facture"
    }]
  }, {
    "date": "2016-02-18",
    "activities": [{
      "type": "bank",
      "icon": {
        "type": "lock-3",
        "color": "#000000"
      },
      "badge": {
        "text": "",
        "color": "#000000",
        "backgroundColor": "transparent"
      },
      "action": null,
      "title": "MOT DE PASSE MODIFIÉ",
      "description": ""
    }]
  }, {
    "date": "2016-02-08",
    "activities": [{
      "type": "bank",
      "icon": {
        "type": "lock-3",
        "color": "#000000"
      },
      "badge": {
        "text": "",
        "color": "#000000",
        "backgroundColor": "transparent"
      },
      "action": null,
      "title": "MOT DE PASSE MODIFIÉ",
      "description": ""
    }]
  }, {
    "date": "2016-02-02",
    "activities": [{
      "type": "client",
      "icon": {
        "type": "document-1",
        "color": "#000000"
      },
      "badge": {
        "text": "0 €",
        "color": "#ffffff",
        "backgroundColor": "#97d42e"
      },
      "action": "724",
      "title": "FACTURE",
      "description": "Test client - F - 00005"
    }, {
      "type": "client",
      "icon": {
        "type": "document-1",
        "color": "#000000"
      },
      "badge": {
        "text": "0 €",
        "color": "#ffffff",
        "backgroundColor": "#97d42e"
      },
      "action": "720",
      "title": "FACTURE",
      "description": "Abus - F - 00004"
    }]
  }, {
    "date": "2016-02-01",
    "activities": [{
      "type": "client",
      "icon": {
        "type": "user-1",
        "color": "#000000"
      },
      "badge": {
        "text": "",
        "color": "#000000",
        "backgroundColor": "transparent"
      },
      "action": 724,
      "title": "NOUVEAU CLIENT",
      "description": "Test client - Scooby"
    }, {
      "type": "client",
      "icon": {
        "type": "document-1",
        "color": "#000000"
      },
      "badge": {
        "text": "1 500 €",
        "color": "#ffffff",
        "backgroundColor": "#97d42e"
      },
      "action": "720",
      "title": "FACTURE",
      "description": "Abus - Fact"
    }, {
      "type": "client",
      "icon": {
        "type": "user-1",
        "color": "#000000"
      },
      "badge": {
        "text": "",
        "color": "#000000",
        "backgroundColor": "transparent"
      },
      "action": 720,
      "title": "NOUVEAU CLIENT",
      "description": "Abus - Busbus"
    }, {
      "type": "document",
      "icon": {
        "type": "download-6",
        "color": "#000000"
      },
      "badge": {
        "text": "",
        "color": "#000000",
        "backgroundColor": "transparent"
      },
      "action": null,
      "title": "7 DOCUMENTS DÉPOSÉS",
      "description": "retrait-par-carte-Invalid date.jpg, Document-01-02-2016.jpg, Doss1, Doss2, Document-01-02-2016.jpg, -Invalid date.jpg, retrait-par-carte-01-02-2016.jpg"
    }, {
      "type": "client",
      "icon": {
        "type": "document-1",
        "color": "#000000"
      },
      "badge": {
        "text": "643,44 €",
        "color": "#ffffff",
        "backgroundColor": "#97d42e"
      },
      "action": "719",
      "title": "FACTURE",
      "description": "Justine - Facture 2"
    }, {
      "type": "bank",
      "icon": {
        "type": "lock-3",
        "color": "#000000"
      },
      "badge": {
        "text": "",
        "color": "#000000",
        "backgroundColor": "transparent"
      },
      "action": null,
      "title": "MOT DE PASSE MODIFIÉ",
      "description": ""
    }, {
      "type": "client",
      "icon": {
        "type": "document-1",
        "color": "#000000"
      },
      "badge": {
        "text": "400 €",
        "color": "#ffffff",
        "backgroundColor": "#97d42e"
      },
      "action": "719",
      "title": "FACTURE",
      "description": "Justine - Ma first facture"
    }, {
      "type": "client",
      "icon": {
        "type": "user-1",
        "color": "#000000"
      },
      "badge": {
        "text": "",
        "color": "#000000",
        "backgroundColor": "transparent"
      },
      "action": 719,
      "title": "NOUVEAU CLIENT",
      "description": "Justine - Arma"
    }, {
      "type": "bank",
      "icon": {
        "type": "flag-1",
        "color": "#000000"
      },
      "badge": {
        "text": "",
        "color": "#000000",
        "backgroundColor": "transparent"
      },
      "action": null,
      "title": "BIENVENUE À BORD DE TIIME AE",
      "description": "C'est parti pour 30 jours offerts"
    }]
  }]
}

我是AngularJS 的新手,我试图只显示datetype,但还没有运气。

任何帮助将不胜感激!

【问题讨论】:

  • 尝试&lt;ul ng-repeat="item in datab"&gt; 然后&lt;li&gt;{{item.date}}&lt;/li&gt;
  • 它运作良好非常感谢你:)
  • @user3130401,请将此作为答案发布,以便我们将其选为正确答案。

标签: arrays angularjs json angularjs-ng-repeat


【解决方案1】:

你可以试试这样的:

<ul ng-repeat="item in datab">
  <li ng-repeat="value in item">
    {{value.date}}
  </li>
</ul>

JSFiddle.

【讨论】:

    【解决方案2】:

    试试这个:

    .controller('HomeCtrl', ['$scope','$stateParams','lastactivities',
     function($scope, $stateParams,lastactivities) {
      var mytoken = sessionStorage.getItem('token');
      lastactivities.send(mytoken).then(function(activities){
    
      var activitytab = activities.data;
    
       var data=[];
    for (var i=0;activities.data.length>0,i++)
    {
        for(var j=0;activities.data[i].activities.length>0;j++)
        {
            data.push({date: activities.data[i].date, Type: activities.data[i].activities[j].type})
        }
    }
    
      $scope.datab = data;
    
      });
     }
    ])
    

    【讨论】:

      猜你喜欢
      • 2015-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多