2014-03-06 4 views
1

나는 구조다단계 목록 메뉴는

(별개!) 범주 목록 다음 접촉을 시도

  • 카테고리 1
  • 카테고리 2
  • 분류 N

각 범주는 범주 내의 게시물에 연결됩니다. :> 컨텐츠가 2 고양이 1

질문 - 그리고 게시물 내용에 링크

  • 후 1 고양이 1 -> 내용 포스트 1 고양이 1
  • 후 2 고양이 2 게시물로 연결되는 카테고리의 고유 목록을 만드는 방법을 모르겠습니다. 어떤 해결책?

    이 내 JSON의 예이다는

    {"status": "ok", 
    "count": 10, 
    "count_total": 20, 
    "pages": 2, 
    "posts": [ 
        { 
         "id": 86, 
         "type": "post", 
         "slug": "inaktiviert", 
         "url": "http://localhost/wordpress/?p=86", 
         "status": "publish", 
         "title": "Post 1 Cat1", 
         "content": "his is content for Post1 Cat 1.", 
         "date": "2014-03-04 15:09:51", 
         "modified": "2014-03-04 15:09:51", 
         "categories": [ 
          { 
           "id": 1, 
           "title": "Category 1", 
           "description": "", 
           "parent": 0, 
           "post_count": 4 
          } 
         ], 
        }, 
        { 
         "id": 84, 
         "type": "post", 
         "slug": "kann-nicht-aktualisiert-werden", 
         "url": "http://localhost/wordpress/?p=84", 
         "status": "publish", 
         "title": "Post 2 Cat1", 
         "content": "<p>This is content for Post2 Cat 1.</p>\n", 
         "date": "2014-03-04 15:09:25", 
         "modified": "2014-03-04 15:09:25", 
         "categories": [ 
          { 
           "id": 1, 
           "title": "Category 1", 
           "description": "", 
           "parent": 0, 
           "post_count": 4 
          } 
         ], 
        }, 
         { 
          "id": 74, 
          "type": "post", 
          "slug": "dieses-symbol-zeigt-an", 
          "url": "http://localhost/wordpress/?p=74", 
          "status": "publish", 
          "title": "Post 1 Cat2", 
          "content": "This is Content for Post1 Cat 2", 
          "date": "2014-03-04 15:06:47", 
          "modified": "2014-03-04 15:06:47", 
          "categories": [ 
           { 
            "id": 2, 
            "title": "Category 2", 
            "description": "", 
            "parent": 0, 
            "post_count": 3 
           } 
          ], 
         } 
        ]} 
    

    그리고

    $(document).on("pagecreate", "#page1", function(){ 
        var liste = $('#liste'); 
    
        var AllListItems = ''; 
        var AllDynamicPages = ''; 
        $.each(daten.posts, function(index1, data) { 
         var postid = data.id; 
         var postTitle = data.title; 
         var postContent = data.content; 
    
         for (var i = 0; i< data.categories.length; i++) { 
    
          var catid = data.categories[i].id;  
          var catTitle = data.categories[i].title;    
          AllListItems += '<li><a href="#page' + postid + '">' + postTitle + '</a></li>';  
          AllDynamicPages += '<div data-role="page" data-add-back-btn="true" id="page' + postid + '"><div data-role="header"><h1>' + postTitle + '</h1></div><div data-role="content">' + postContent + '</div></div>' 
         }   
        }); 
    
        liste.empty().append(AllListItems).listview("refresh"); 
        $("body").append(AllDynamicPages); 
    }); 
    

    DEMO

+0

무엇이 문제입니까? –

+0

JSON이 올바르지 않습니다. 그것을 실행 [JSONLint] (http://jsonlint.com/) –

+0

@SandeepNayak 죄송합니다, 내 질문을 업데이트했습니다. 외부 JSON에 대한 – mariell

답변