简体   繁体   English

显示来自json的数据

[英]display data from json

I am having problem in displaying data in listview from json format,this is my code that i have used to do this: 我在以json格式在listview中显示数据时遇到问题,这是我用来执行此操作的代码:

<div data-role="view" data-title="Home" data-layout="main" data-model="APP.models.home" id="bloggerView" data-show="showBloggers">
    <h1 data-bind="html: title"></h1>


    <ul id="bloggerList"
        data-source="bloggersData"
        data-endlessScroll="true"
        data-template="bloggersTemplate"
        data-role="listview"
        data-style="inset"></ul>

    </div>

    <script id="bloggersTemplate" type="text/x-kendo-template">

        <a href="\#BloggerDetailsView" class="km-listview-link" data-role="listview-link">
            <h2>#=data.id#</h2>
            <h4>#=data.nom#</h4>
        </a>
        </script>
    <script type="text/javascript">
        jQuery.support.cors = true;
     var bloggersData;
            bloggersData=new kendo.data.DataSource(
            {
            transport :{
            read: {
                url: "http://127.0.0.1:8080/webservicesV1/cuisines.php",
                type: "Get",
                data: {

            }
            }
            }
            });
            function showBloggers() {
                bloggersData.fetch();
                console.log(JSON.stringify(bloggersData.data()));
                console.log("test_fetch");
            }


    </script>

this is my json data: 这是我的json数据:

{
success: 1,
message: "cuisine trouve!",
cuisines: [
{
id: "1",
nom: "maltaine"
},
{
id: "2",
nom: "française"
}
]
}

this is what I get as a result in console,and an undified values in my list: 这是我在控制台中得到的结果,并且列表中的值不统一:

VM220:17 []
VM220:18 test_fetch

thanks for help 感谢帮助

Pass a callback to the fetch method: 将回调传递给fetch方法:

bloggersData.fetch(function () {
    console.log(JSON.stringify(this.data()));
    console.log("test_fetch");
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM