Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.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 将JSON导入html(表)筛选结果_Javascript_Html_Json_Import_Html Table - Fatal编程技术网

Javascript 将JSON导入html(表)筛选结果

Javascript 将JSON导入html(表)筛选结果,javascript,html,json,import,html-table,Javascript,Html,Json,Import,Html Table,我正在尝试将JSON数据导入html表。我有不同类型的数据。在我的例子中,我只需要查看表中的“link”数据类型,这就是我得到的JSON数据 { "data": [ { "type": "photo", "created_time": "2017-11-15T14:30:43+0000", "permalink_url": "https://www.facebook.com/LaFokaES/posts/693061044378702", "s

我正在尝试将JSON数据导入html表。我有不同类型的数据。在我的例子中,我只需要查看表中的“link”数据类型,这就是我得到的JSON数据

  {   "data": [
  {
     "type": "photo",
     "created_time": "2017-11-15T14:30:43+0000",
     "permalink_url": "https://www.facebook.com/LaFokaES/posts/693061044378702",
     "shares": {
        "count": 2270
     },
     "id": "104957429855736_693061044378702"
  },
  {
     "type": "link",
     "created_time": "2017-11-15T02:34:46+0000",
     "permalink_url": "https://www.facebook.com/LaFokaES/posts/692656794419127",
     "shares": {
        "count": 86
     },
     "id": "104957429855736_692656794419127"
  },
  {
     "type": "photo",
     "created_time": "2017-11-15T00:34:50+0000",
     "permalink_url": "https://www.facebook.com/LaFokaES/posts/692493157768824",
     "shares": {
        "count": 1628
     },
     "id": "104957429855736_692493157768824"
  },
  {
     "type": "photo",
     "created_time": "2017-11-14T23:51:53+0000",
     "permalink_url": "https://www.facebook.com/LaFokaES/posts/692442954440511",
     "shares": {
        "count": 6239
     },
     "id": "104957429855736_692442954440511"
这是我的代码:

   <body>
    <input type="text" class="txtPagina">
    <button class="btnBuscar">Buscar</button>
    <table class="tabla" border='1'>
         <tr>

             <td>Type</td>
          <td>created time</td>
             <td>permalink url</td>
             <td>Shares Count</td>


         </tr>
    </table>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>


     $(document).ready(function(){
            $('.btnBuscar').on('click', function (){
                var pagina = $('.txtPagina').val();
            //Ajax
            $.ajax({
                type: "GET",
                dataType: "json",
                url: "https://graph.facebook.com/"+pagina+"/feed?fields=type,created_time,permalink_url,shares&limit=25& access_token=(mytoken)",
                success: function(data){


     $.each(data.data, function(i, d){
        var s = d.shares ? '<td>'+d.shares.count+'</td>' : '';
        $('.tabla').append('<tr><td>'+d.type+'</td><td>'+d.created_time+'</td><td>'+d.permalink_url+'</td>'+s+'</tr>');
      });
    },
                    error: function (){
                        console.log("Error");

客车
类型
创造时间
永久链接
股数
$(文档).ready(函数(){
$('btnBuscar')。在('click',函数(){
var pagina=$('.txtPagina').val();
//阿贾克斯
$.ajax({
键入:“获取”,
数据类型:“json”,
url:“https://graph.facebook.com/“+pagina+”/feed?fields=type,created\u time,permalink\u url,shares&limit=25&access\u token=(mytoken)”,
成功:功能(数据){
$.each(数据、数据、函数(i、d){
var s=d.shares?''+d.shares.count+'':;
$('.tabla').append(''+d.type+''+d.created\u time+''+d.permalink\u url+''+s+'');
});
},
错误:函数(){
控制台日志(“错误”);
这就是我得到的结果:


正如您所看到的,我正在获取照片和链接,但我只需要查看链接。

只需在循环中添加if语句即可过滤掉照片

 $.each(data.data, function(i, d){
      if(d.type =='link'){
      var s = d.shares ? '<td>'+d.shares.count+'</td>' : '';
    $('.tabla').append('<tr><td>'+d.type+'</td><td>'+d.created_time+'</td><td>'+d.permalink_url+'</td>'+s+'</tr>');
    }
  });
$。每个(数据、数据、函数(i、d){
如果(d.type=='link'){
var s=d.shares?''+d.shares.count+'':;
$('.tabla').append(''+d.type+''+d.created\u time+''+d.permalink\u url+''+s+'');
}
});

只需在循环中添加一个if语句即可过滤掉照片

 $.each(data.data, function(i, d){
      if(d.type =='link'){
      var s = d.shares ? '<td>'+d.shares.count+'</td>' : '';
    $('.tabla').append('<tr><td>'+d.type+'</td><td>'+d.created_time+'</td><td>'+d.permalink_url+'</td>'+s+'</tr>');
    }
  });
$。每个(数据、数据、函数(i、d){
如果(d.type=='link'){
var s=d.shares?''+d.shares.count+'':;
$('.tabla').append(''+d.type+''+d.created\u time+''+d.permalink\u url+''+s+'');
}
});
在每个循环中:

if(d.type == 'link') {
    //Add as you already do
}
完成!

在每个循环中:

if(d.type == 'link') {
    //Add as you already do
}
完成了!

不仅仅是
'
就够了吗?什么叫“我只需要查看链接”?这不是你自己的代码吗?更改它,让它显示你想要的东西。不仅仅是
'
就够了吗?什么叫“我只需要查看链接”?这不是你自己的代码吗?更改它,让它显示你想要的东西。