angular.js - Angular根據JSON資料動態產生在網頁上的列表
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-15 16:56:22
0
1
642
[
  {
    "meta": {
      "author": "test", 
      "date_create": "2015-10-14T00:00:00", 
      "date_modify": "2015-10-14T00:00:00", 
      "filename": "微信页面整合", 
      "git_username": "kk", 
      "subdir": "article", 
      "subtitle": null, 
      "tags": [
        "api", 
        "微信", 
        "开发文档"
      ], 
      "title": "微信页面整合"
    }
  }, 
  {
    "meta": {
      "author": "Waylan LimbergJohn Doe", 
      "date_create": "2015-10-14T00:00:00", 
      "date_modify": "2015-10-14T00:00:00", 
      "filename": "python2编码问题.md", 
      "git_username": "guyskk", 
      "subdir": "article", 
      "subtitle": null, 
      "tags": [], 
      "title": "python2编码问题"
    }
  }
]

json檔案格式如上,如何透過angular根據傳回的json檔案(可能有多個文章資料),動態產生清單。要求能讀取到meta和title。 。第一次用angular,卡在這種數組套對象,對象裡面又是對象的模式了。 。 。好幾天了。

謝謝!

曾经蜡笔没有小新
曾经蜡笔没有小新

全部回覆(1)
给我你的怀抱

用ng-repeat應該很容易做吧
範例(http://plnkr.co/edit/xsQqAFUiwigPEkbyNtdO)

html

<!DOCTYPE html>
<html ng-app="plunker">

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.4.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.6/angular.min.js" data-semver="1.4.6"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p ng-repeat="ele in data">
      <p>{{ele.meta.author}}</p>
      <p>{{ele.meta.title}}</p>
      <br>
    </p>
  </body>

</html>

js

var app = angular.module('plunker', []);

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
  $scope.data = [
      {
        "meta": {
          "author": "test", 
          "date_create": "2015-10-14T00:00:00", 
          "date_modify": "2015-10-14T00:00:00", 
          "filename": "微信页面整合", 
          "git_username": "kk", 
          "subdir": "article", 
          "subtitle": null, 
          "tags": [
            "api", 
            "微信", 
            "开发文档"
          ], 
          "title": "微信页面整合"
        }
      }, 
      {
        "meta": {
          "author": "Waylan LimbergJohn Doe", 
          "date_create": "2015-10-14T00:00:00", 
          "date_modify": "2015-10-14T00:00:00", 
          "filename": "python2编码问题.md", 
          "git_username": "guyskk", 
          "subdir": "article", 
          "subtitle": null, 
          "tags": [], 
          "title": "python2编码问题"
        }
      }
    ];
});
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!