wordpress 用の「json-API」プラグインを使用しており、その情報を phonegap アプリに呼び出そうとしています。
http://alexbachuk.com/wordpress-and-phonegap-part3/の投稿をフォローしており、コンテンツで custom_fields を呼び出す方法を見つけようとしています。
次のようなカスタム フィールドを含めました: ' http://www.example.com/?json=get_recent_posts&custom_fields=store-icon ' ajax リクエストに。
ajax リクエストは次のようになります。
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 を解析しているため、投稿のタイトルは {{title}} として出力され、サムネイルは {{thumbnail}} として出力されます。同様の方法で custom_fields を出力する方法はありますか?