Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按id检索帖子_Javascript_Json_Angularjs_Wordpress_Http - Fatal编程技术网

Javascript 按id检索帖子

Javascript 按id检索帖子,javascript,json,angularjs,wordpress,http,Javascript,Json,Angularjs,Wordpress,Http,我从WordPress接收到一个JSON对象,如下所示 { "ID": 4164, "title": "24 Horas Non-Stop con Marco Carola", "status": "publish", "type": "post", "author": { "ID": 11, "username": "VIlma Quiros",

我从WordPress接收到一个JSON对象,如下所示

{
        "ID": 4164,
        "title": "24 Horas Non-Stop con Marco Carola",
        "status": "publish",
        "type": "post",
        "author": {
            "ID": 11,
            "username": "VIlma Quiros",
            "registered": "2015-04-16T07:04:04+00:00",
            "meta": {
                "links": {
                    "self": "http://urbanetradio.com/wp-json/users/11",
                    "archives": "http://urbanetradio.com/wp-json/users/11/posts"
                }
            }
        },
        "content": "<p class=\"p2\"><a href= 
这里是控制器

.controller('NewsCtrl', function($scope, FreshlyPressed) {

  $scope.posts = [];

  $scope.doRefresh = function() {
    $scope.posts = FreshlyPressed.getBlogs($scope);
    $scope.$broadcast('scroll.refreshComplete');
  }
  $scope.doRefresh();

});
这就是我想要的:

在这个视图中,我只显示文章的标题和日期,这是主视图

  <a ng-href="#/tabs/news/{{post.ID}}">
    <h2 ng-bind-html="post.title"></h2>
    <p>{{:: post.date | date}}</p>
  </a>
我得到这个错误


GEThttp://urbanetradio.com/wp-json/posts/postId 404(未找到)

我想您需要像这样更改此函数

  getPostById: function(postId) {
      var url ='http://urbanetradio.com/wp-json/posts/'+ postId;
      return $http.get(url);
根据您的代码,postId是要在字符串中替换的参数,而不是像在代码中一样在字符串中追加值

您需要像这样调用方法

   FreshlyPressed.getPostById(1);//1 is postid value 

@卢克,看看路线和密码。应该是
urbanetradio.com/wp json/posts/{{post.ID}
??我得到
GEThttp://urbanetradio.com/wp-json/posts/undefined 404(未找到)
在何处调用
getPostById
?@NietzscheProgrammer-调用functions@radonirinamaina时,需要传递postId值,我刚刚意识到,当我调用getPostById时,我没有传递参数,对不起,谢谢:)
//the route for the main view

.state('tabs.news', {
    url: '/news',
    views: {
      'tab-news': {
        templateUrl: 'templates/tab-news.html',
        controller: 'NewsCtrl'
      }
    }
  })

//the route for the second view where you will see the entire post

.state('tabs.post-detail', {
  url: '/news/:postId',
  views: {
    'tab-news': {
      templateUrl: 'templates/tab-post-detail.html',
      controller: 'PostDetailCtrl'
    }
  }
})
  getPostById: function(postId) {
      var url ='http://urbanetradio.com/wp-json/posts/'+ postId;
      return $http.get(url);
   FreshlyPressed.getPostById(1);//1 is postid value