0

我正在使用 wordpress 的“json-API”插件,我正在尝试将该信息调用到 phonegap 应用程序中。

我正在关注http://alexbachuk.com/wordpress-and-phonegap-part3/上的帖子,我正在尝试找出如何在我的内容中调用 custom_fields。

我在 ajax 请求中包含了这样的自定义字段:' http://www.example.com/?json=get_recent_posts&custom_fields=store-icon '。

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?

4

1 回答 1

0

就在这里。

利用:

{{custom_fields.fieldname}}
于 2014-09-13T10:48:44.480 回答