【问题标题】:display data from json显示来自 json 的数据
【发布时间】:2015-11-08 20:25:06
【问题描述】:

我在以 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>

这是我的 json 数据:

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

这是我在控制台中得到的结果,以及我列表中的未定义值:

VM220:17 []
VM220:18 test_fetch

感谢帮助

【问题讨论】:

    标签: javascript kendo-ui kendo-mobile


    【解决方案1】:

    将回调传递给fetch 方法:

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

    【讨论】:

    • 感谢 mic4ael 的回复,但我的列表中仍未定义 :(
    • 对不起,我弄错了。试试我现在提供的代码。
    • 我在控制台中得到了这个:["{","\"","s","u","c","c","e","s","s ","\"",":","1",",","\"","m","e","s","s","a","g","e ","\"",":","\"","c","u","i","s","i","n","e"," ","t" ,"r","o","u","v","e","!","\"",",","\"","c","u","i" ,"s","i","n","e","s","\"",":","[","{","\"","i","d" ,"\"",":","\"","1","\"",",","\"","n","o","m","\"", ":","\"","m","a","l","t","a","i","n","e""\"","}"," ,","{","\"","i","d","\"",":","\"","2","\"",",","\" ","n","o","m","\"",":","\"","f","r","a","n","ç","a ","i","s","e","\"","}","]","}"] VM427:18 test_fetch
    • 并且在视图中没有定义:(
    猜你喜欢
    • 2022-01-13
    • 2021-11-28
    • 1970-01-01
    • 1970-01-01
    • 2022-12-23
    • 2018-05-09
    • 2018-12-28
    • 1970-01-01
    相关资源
    最近更新 更多