json javascript,在

时间:2016-12-19 03:35:58

标签: javascript json

我有一个帖子列表,想要在与其关联的每个类别下的列表(li)中显示帖子,问题是我得到一个空白而没有添加类别或列表..让我知道我做错了什么

我希望列表看起来像这样

  1. 类别 发布
    发布
    发布

    function recentPosts(data) {
       "use strict";
    
        $.each(data.posts, function(key, val) {
    
        var output = ' <div data-role="page" class="jqm-demos" id=" ' + val.slug + ' " data-title="Panel fixed positioning">';
    
        output += '<div data-role="header" class="ui-nodisc-icon" data-add-back-btn="true" data-position="fixed" data-tap-toggle="false" data-back-btn-text="">';
        output += '<h1> ' + val.title + '</h1>';
    
        output += '<p class="company-name"> company name </p>';
        output += '<a href="#benefits-facts" class="ui-btn-right ui-btn ui-btn-b ui-btn-inline ui-mini ui-corner-all ui-btn-icon-notext ui-btn-icon-right ui-icon-home">  </a> </div>';
    
        output += '<div data-role="content" id="health-care-hc-plans-postlist" class="ui-content jqm-content jqm-fullwidth"> ';
    
        output += '<ul  data-role="listview" data-filter="true" data-filter-placeholder="Search..." >';
    
    // $.each(data.posts, function(key, val) {
    
    //     if(v.categories.slug === val.categories.slug) { 
    //     output += '<li>';
    //     output += '<a href="#' + val.slug + '">';
    //     output += '<h3>' + val.title + "</h3>";
    //     output += '</a>';
    //     output += '</li>';
    //     }
    
    // }); //go through each post
    
        output += '</ul> </div> ';
    
        output += ' <div data-role="footer" data-position="fixed" data-tap-toggle="false"> <h4> <a href="#info" data-transition="pop"> &copy; 2017 Michael F. Yates & Company, Inc. </a> </h4> </div>';
    
        output += '</div> ';
    
    }); //go through each post
    
    //$('#quick-facts').after(output);
    $('#newsletter2').after(output);
    }
    
    
    
    
     recentPosts(data);
    
    
    recentPosts({  
       "status":"ok",
       "count":10,
       "count_total":44,
       "pages":5,
       "posts":[  
          {  
             "id":185,
             "type":"benefits",
             "slug":"abbreviations-used",
             "status":"publish",
             "title":"Abbreviations Used",
             "title_plain":"Abbreviations Used",
             "content":"",
             "excerpt":"",
             "date":"2016-12-09 05:30:55",
             "modified":"2016-12-19 00:35:50",
             "categories":[  
                {  
                   "id":12,
                   "slug":"abbreviations-used",
                   "title":"Abbreviations Used",
                   "description":"",
                   "parent":0,
                   "post_count":1
                }
             ],
             "tags":[  
    
             ],
             "author":{  
                "id":5,
                "slug":"brodie",
                "name":"brodie",
                "first_name":"",
                "last_name":"",
                "nickname":"brodie",
                "url":"",
                "description":""
             },
             "comments":[  
    
             ],
             "attachments":[  
    
             ],
             "comment_count":0,
             "comment_status":"closed",
             "custom_fields":{  
    
             }
          },
          {  
             "id":184,
             "type":"benefits",
             "slug":"hc-flexible-spending-fsa-contributions",
             "status":"publish",
             "title":"HC Flexible Spending (FSA) Contributions",
             "title_plain":"HC Flexible Spending (FSA) Contributions",
             "content":"",
             "excerpt":"",
             "date":"2016-12-09 05:30:01",
             "modified":"2016-12-09 05:30:01",
             "categories":[  
                {  
                   "id":11,
                   "slug":"health-care-hc-plans",
                   "title":"Health Care (HC) Plans",
                   "description":"",
                   "parent":0,
                   "post_count":1
                }
             ],
             "tags":[  
    
             ],
             "author":{  
                "id":5,
                "slug":"brodie",
                "name":"brodie",
                "first_name":"",
                "last_name":"",
                "nickname":"brodie",
                "url":"",
                "description":""
             },
             "comments":[  
    
             ],
             "attachments":[  
    
             ],
             "comment_count":0,
             "comment_status":"closed",
             "custom_fields":{  
    
             }
          },
          {  
             "id":182,
             "type":"benefits",
             "slug":"dcfsa-married",
             "status":"publish",
             "title":"DCFSA Married",
             "title_plain":"DCFSA Married",
             "content":"",
             "excerpt":"",
             "date":"2016-12-09 05:24:05",
             "modified":"2016-12-09 05:24:05",
             "categories":[  
                {  
                   "id":23,
                   "slug":"dependent-care-fsa-dcfsa",
                   "title":"Dependent Care FSA (DCFSA)",
                   "description":"",
                   "parent":4,
                   "post_count":2
                }
             ],
             "tags":[  
    
             ],
             "author":{  
                "id":5,
                "slug":"brodie",
                "name":"brodie",
                "first_name":"",
                "last_name":"",
                "nickname":"brodie",
                "url":"",
                "description":""
             },
             "comments":[  
    
             ],
             "attachments":[  
    
             ],
             "comment_count":0,
             "comment_status":"closed",
             "custom_fields":{  
    
             }
          },
          {  
             "id":181,
             "type":"benefits",
             "slug":"what-is-a-dcfsa",
             "status":"publish",
             "title":"What is a DCFSA",
             "title_plain":"What is a DCFSA",
             "content":"",
             "excerpt":"",
             "date":"2016-12-09 05:23:45",
             "modified":"2016-12-09 05:23:45",
             "categories":[  
                {  
                   "id":23,
                   "slug":"dependent-care-fsa-dcfsa",
                   "title":"Dependent Care FSA (DCFSA)",
                   "description":"",
                   "parent":4,
                   "post_count":2
                }
             ],
             "tags":[  
    
             ],
             "author":{  
                "id":5,
                "slug":"brodie",
                "name":"brodie",
                "first_name":"",
                "last_name":"",
                "nickname":"brodie",
                "url":"",
                "description":""
             },
             "comments":[  
    
             ],
             "attachments":[  
    
             ],
             "comment_count":0,
             "comment_status":"closed",
             "custom_fields":{  
    
             }
          },
          {  
             "id":180,
             "type":"benefits",
             "slug":"eligible-tax-exempt-employer",
             "status":"publish",
             "title":"Eligible Tax-Exempt Employer",
             "title_plain":"Eligible Tax-Exempt Employer",
             "content":"",
             "excerpt":"",
             "date":"2016-12-09 05:20:11",
             "modified":"2016-12-09 05:20:11",
             "categories":[  
                {  
                   "id":22,
                   "slug":"small-business-hc-tax-credit",
                   "title":"Small Business HC Tax Credit",
                   "description":"",
                   "parent":11,
                   "post_count":3
                }
             ],
             "tags":[  
    
             ],
             "author":{  
                "id":5,
                "slug":"brodie",
                "name":"brodie",
                "first_name":"",
                "last_name":"",
                "nickname":"brodie",
                "url":"",
                "description":""
             },
             "comments":[  
    
             ],
             "attachments":[  
    
             ],
             "comment_count":0,
             "comment_status":"closed",
             "custom_fields":{  
    
             }
          },
          {  
             "id":179,
             "type":"benefits",
             "slug":"small-employer",
             "status":"publish",
             "title":"Small Employer",
             "title_plain":"Small Employer",
             "content":"",
             "excerpt":"",
             "date":"2016-12-09 05:19:45",
             "modified":"2016-12-09 05:19:45",
             "categories":[  
                {  
                   "id":22,
                   "slug":"small-business-hc-tax-credit",
                   "title":"Small Business HC Tax Credit",
                   "description":"",
                   "parent":11,
                   "post_count":3
                }
             ],
             "tags":[  
    
             ],
             "author":{  
                "id":5,
                "slug":"brodie",
                "name":"brodie",
                "first_name":"",
                "last_name":"",
                "nickname":"brodie",
                "url":"",
                "description":""
             },
             "comments":[  
    
             ],
             "attachments":[  
    
             ],
             "comment_count":0,
             "comment_status":"closed",
             "custom_fields":{  
    
             }
          },
          {  
             "id":178,
             "type":"benefits",
             "slug":"what-is-the-tax-credit",
             "status":"publish",
             "title":"What is the Tax Credit",
             "title_plain":"What is the Tax Credit",
             "content":"",
             "excerpt":"",
             "date":"2016-12-09 05:19:17",
             "modified":"2016-12-09 05:19:17",
             "categories":[  
                {  
                   "id":22,
                   "slug":"small-business-hc-tax-credit",
                   "title":"Small Business HC Tax Credit",
                   "description":"",
                   "parent":11,
                   "post_count":3
                }
             ],
             "tags":[  
    
             ],
             "author":{  
                "id":5,
                "slug":"brodie",
                "name":"brodie",
                "first_name":"",
                "last_name":"",
                "nickname":"brodie",
                "url":"",
                "description":""
             },
             "comments":[  
    
             ],
             "attachments":[  
    
             ],
             "comment_count":0,
             "comment_status":"closed",
             "custom_fields":{  
    
             }
          },
          {  
             "id":177,
             "type":"benefits",
             "slug":"affordable-care-act-hdhp",
             "status":"publish",
             "title":"Affordable Care Act HDHP",
             "title_plain":"Affordable Care Act HDHP",
             "content":"",
             "excerpt":"",
             "date":"2016-12-09 05:17:54",
             "modified":"2016-12-09 05:17:54",
             "categories":[  
                {  
                   "id":21,
                   "slug":"high-deductible-health-plans-hdhp",
                   "title":"High-Deductible Health Plans (HDHP)",
                   "description":"",
                   "parent":11,
                   "post_count":4
                }
             ],
             "tags":[  
    
             ],
             "author":{  
                "id":5,
                "slug":"brodie",
                "name":"brodie",
                "first_name":"",
                "last_name":"",
                "nickname":"brodie",
                "url":"",
                "description":""
             },
             "comments":[  
    
             ],
             "attachments":[  
    
             ],
             "comment_count":0,
             "comment_status":"closed",
             "custom_fields":{  
    
             }
          },
          {  
             "id":176,
             "type":"benefits",
             "slug":"hdhp-max-out-of-pocket",
             "status":"publish",
             "title":"HDHP Max. Out-of-Pocket",
             "title_plain":"HDHP Max. Out-of-Pocket",
             "content":"",
             "excerpt":"",
             "date":"2016-12-09 05:17:30",
             "modified":"2016-12-09 05:17:30",
             "categories":[  
                {  
                   "id":21,
                   "slug":"high-deductible-health-plans-hdhp",
                   "title":"High-Deductible Health Plans (HDHP)",
                   "description":"",
                   "parent":11,
                   "post_count":4
                }
             ],
             "tags":[  
    
             ],
             "author":{  
                "id":5,
                "slug":"brodie",
                "name":"brodie",
                "first_name":"",
                "last_name":"",
                "nickname":"brodie",
                "url":"",
                "description":""
             },
             "comments":[  
    
             ],
             "attachments":[  
    
             ],
             "comment_count":0,
             "comment_status":"closed",
             "custom_fields":{  
    
             }
          },
          {  
             "id":175,
             "type":"benefits",
             "slug":"hdhp-min-deductibles",
             "status":"publish",
             "title":"HDHP Min. Deductibles",
             "title_plain":"HDHP Min. Deductibles",
             "content":"",
             "excerpt":"",
             "date":"2016-12-09 05:17:01",
             "modified":"2016-12-09 05:17:01",
             "categories":[  
                {  
                   "id":21,
                   "slug":"high-deductible-health-plans-hdhp",
                   "title":"High-Deductible Health Plans (HDHP)",
                   "description":"",
                   "parent":11,
                   "post_count":4
                }
             ],
             "tags":[  
    
             ],
             "author":{  
                "id":5,
                "slug":"brodie",
                "name":"brodie",
                "first_name":"",
                "last_name":"",
                "nickname":"brodie",
                "url":"",
                "description":""
             },
             "comments":[  
    
             ],
             "attachments":[  
    
             ],
             "comment_count":0,
             "comment_status":"closed",
             "custom_fields":{  
    
             }
          }
       ],
       "query":{  
          "ignore_sticky_posts":true,
          "callback":"recentPosts"
       }
    });
    

0 个答案:

没有答案