javascript - Kendo UI 移动 ListView 示例不适用于我的代码

标签 javascript json mobile kendo-ui

背景:在一些帮助 (@korchev) 的帮助下,我能够弄清楚如何使用 JSONP 将数据绑定(bind)到模板。 (参见thisthis question)。但是,我希望能够使数据显示在 kendo UI Mobile List View 中,如 the Kendo Docs 中所述。 .

不幸的是,移动 ListView example ,使用 html 中编码的数据数组,这与 jsonp 不同。

另外,我注意到官方mobile list-view example忽略这一点:<script type="text/x-kendo-template" id="template"> 。这是一个问题,因为我的 code依赖于该实现。

摘要:我是 kendo UI 移动框架的新手,我不明白如何使用现有代码生成移动 ListView 。有时我发现文档令人困惑,我希望有人能提供帮助。

我的代码:

<div id="products"></div>

<script type="text/x-kendo-template" id="template">
    <div class="product">
        <p>#:title#</p>
        <p>#:content#</p>
        <p>#= author.slug #</p>
    </div>
</script>

   <script>

$(function() {
        var template = kendo.template($("#template").html());

        var dataSource = new kendo.data.DataSource({
            schema: {
                data: function(response) {
                    return [response.post];
                }
            },
            transport: {
                read: {
                    url: "http://www.techhelix.com/?json=get_post&id=1/",
                    dataType: "jsonp"
                }
            },
            requestStart: function() {

                kendo.ui.progress($("#products"), true);
            },
            requestEnd: function() {

               kendo.ui.progress($("#products"), false);
               console.log(JSON.stringify(dataSource, null, 4));

            },
            change: function() {

               $("#products").html(kendo.render(template, this.view()));
            }

        });

        dataSource.read();

    });
</script>

最佳答案

Daniel,我首先会从 Kendo Mobile List View 示例开始并使其正常工作。 一旦成功,您可以执行以下操作来绑定(bind)到您的数据源和模板。

function mobileListViewDataBindInitGrouped() {

    ...Code for getting your dataSource here...

    $("#products").kendoMobileListView({
        dataSource: dataSource,
        template: kendo.template($("#template").html()),
        fixedHeaders: true
    });
}

关于javascript - Kendo UI 移动 ListView 示例不适用于我的代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22285040/

相关文章:

javascript - 带有验证控件的 ASP.NET 和 jQuery 出现奇怪的 Javascript 错误

json - 使用 jq 获取数组的所有值

ios - 在 Alamofire 中发送 JSONObject

javascript - 在 Javascript 中显示重音字符

javascript - 我可以在哪个文件中放置一个脚本来清除 Titanium 应用程序的缓存

javascript - 此实验性语法需要启用以下解析器插件之一 : 'classPrivateProperties, classPrivateMethods'

javascript - 我的 For 循环计时不正确,出了什么问题?

javascript - 给html5 canvas上的绘制对象添加事件监听器

jquery - CarouFredSel 使分页响应

database - 需要客户端同步本地数据库的移动数据库