【问题标题】:Selecting the first JSON array + filter by word选择第一个 JSON 数组 + 按单词过滤
【发布时间】:2012-03-30 06:54:32
【问题描述】:

我正在使用 jQuery 创建一个 Facebook 页面,并且我想过滤一个帖子。但我似乎无法弄清楚如何。我对jQuery不是很有经验,但正在学习。

所以我想用井号标签过滤掉#weekhap 字样,以便所有者更轻松地管理 Facebook 上的所有内容。这甚至可能吗?我正在使用此代码:

function fbFetchWeekhap(){
  var url = "https://graph.facebook.com/reindersrobin/posts&access_token=AAAE6AYdEq9sBALPKSIgPUDrdQIy2aHZBQSQI9DuhY1yx9z1ZC1p8TVLTCCIuZBZAgw1ann9iyghVGPLwsTRwOJZAC8a6M53YZD";  
    $.getJSON(url,function(json){
            console.log(json)   
                $.each(json.data,function(i,fb){
                    var html = fb.message;
                $("#weekhap").html(html);     
                });
            });  
};

Facebook JSON 正在生成这个:

"data": [
    {
      "id": "401455409880061_417873164904952", 
      "from": {
        "name": "ReindersRobin", 
        "category": "Bar", 
        "id": "401455409880061"
      }, 
      "message": "#weekhap", 
      "actions": [
        {
          "name": "Comment", 
          "link": "http://www.facebook.com/401455409880061/posts/417873164904952"
        }, 
        {
          "name": "Like", 
          "link": "http://www.facebook.com/401455409880061/posts/417873164904952"
        }
      ], 
      "privacy": {
        "description": "Public", 
        "value": "EVERYONE"
      }, 
      "type": "status", 
      "created_time": "2012-03-30T05:58:09+0000", 
      "updated_time": "2012-03-30T05:58:09+0000", 
      "comments": {
        "count": 0
      }, 
      "is_published": true
    }, 

【问题讨论】:

    标签: jquery facebook json filter


    【解决方案1】:
    function fbFetchWeekhap( filter_word ){ 
        var url = "https://graph.facebook.com/reindersrobin/posts&access_token=ACCESS_TOKEN";
        $.getJSON(url,function(json){ 
            console.log(json);
            $.each(json.data,function(i,fb){
                var html = fb.message;
                if( fb.messsage == filter_word){ # filter here
                    $("#weekhap").append('<p>'+html+'</p>');
                }
            }); 
        });
    };
    

    使用fbFetchWeekhap('#weekhap');

    【讨论】:

    • 谢谢,这行得通:-) 但现在我需要弄清楚如何显示包含标签的帖子。但我先试试我自己。
    • 我似乎无法弄清楚,我想使用 IndexOf 对吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-22
    • 2021-09-29
    • 1970-01-01
    • 1970-01-01
    • 2019-03-13
    • 1970-01-01
    • 2011-07-24
    相关资源
    最近更新 更多