2014-05-14 8 views
0

나는 "json-API"플러그인을 사용하여 wordpress에 대한 정보를 phonegap 앱에 호출하려고합니다.wordpress json api phonegap handlebars custom_fields

나는 http://alexbachuk.com/wordpress-and-phonegap-part3/에 대한 소식을 받고 있으며 내 콘텐츠에서 custom_fields를 호출하는 방법을 찾으려고합니다.

저는 AYax 요청에 'http://www.example.com/?json=get_recent_posts&custom_fields=store-icon'과 같은 사용자 정의 필드를 포함 시켰습니다.

product: function(){ 
     function getProducts() { 
      var dfd = $.Deferred(); 

      $.ajax({ 
       url: 'http://delectable.site40.net/blog/?json=get_recent_posts&custom_fields=store-icon', 
       type: 'GET', 
       dataType: 'json', 
       success: function(data){ 
        var source = $("#product-template").html(); 
        var template = Handlebars.compile(source); 
        var blogData = template(data); 
        $('#product-data').html(blogData); 
        $('#product-data').trigger('create'); 
        dfd.resolve(data); 

       }, 
       error: function(data){ 
        console.log(data); 
       } 
      }); 
      return dfd.promise(); 
     }; 

     getProducts().then(function(data){ 
      $('#all-posts').on('click','li', function(e){     
       localStorage.setItem('postData', JSON.stringify(data.posts[$(this).index()])); 
      }); 
     }); 


    } 

및 템플릿은 현재 다음과 같습니다 :

아약스 요청은 다음과 같습니다

<script id="product-template" type="text/x-handlebars-template"> 
      <ul data-role="listview" data-icon="false" class="mainContent" data-theme="a" id="all-posts"> 

      {{#each posts}} 

       <li class="center productss"><p class="photo circle center" style="margin-left: 31%;"><img src="{{thumbnail}}" width="85" height="57" /></ br><a data-ajax="false" data-transition="slide" href="single.html?{{@index}}"><h3 class="main_product">{{title}}</h3></a></ br><h5 class="left">R4200-00</h5><h5 class="right"><img src="{{custom_fields[0].url}}" width="150" height="20" /></h5></p></li> 

      {{/each}} 
      </ul> 
     </script> 

는 어떻게 HTML로 그를 삽입하는 방법에 대한 갈 것입니다. alexbachuk.com 게시물은 핸들 막대를 사용하여 json을 구문 분석하므로 게시물 제목은 {{제목}}으로 출력되고 썸네일은 {{미리보기}}로 출력됩니다. 유사한 방식으로 custom_fields를 출력하는 방법이 있습니까?

답변

0

예 있습니다.

사용 :

{{custom_fields.fieldname}}