【问题标题】:data binding in Kendo mobileKendo mobile中的数据绑定
【发布时间】:2012-04-13 10:56:32
【问题描述】:

我正在做一个剑道移动应用程序,我正在尝试从数据库中绑定数据以使用 json 调用列出。我尝试使用以下代码,但它不起作用请帮我解决这个问题...在此先感谢...

我的代码在这里:

        $(document).ready(function () {

            var dataSource = new kendo.data.DataSource({
                transport: {
                    read: {
                        type: "POST",
                        url: "WebService/listing.php",
                        contentType: 'application/json; charset=utf-8',
                        datatype: "json"
                    }
                }
            });

            dataSource.bind("change", function () {
                $("#content").html(kendo.render(template, dataSource.view()));
            });

            dataSource.read();
            console.log(dataSource.view());

        });

【问题讨论】:

  • 您的服务对 Internet 可见吗?

标签: json data-binding kendo-ui kendo-mobile


【解决方案1】:

您可以尝试直接使用数据源的change函数:

var dataSource = new kendo.data.DataSource({
    transport: {
        read: {
            type: "POST",
            url: "WebService/listing.php",
            contentType: 'application/json; charset=utf-8',
            datatype: "json"
        }
    },
    change: function() {
        $("#content").html(kendo.render(template, this.view()));
    }
});

只是需要考虑的一些事项:

  • 我假设您的 JSON 是正确的
  • 您确定使用 POST 获取数据
  • 您的模板定义正确
  • 在加载数据后调用dataSource.read()(为确保这样做,请在$(document).ready(function(){dataSource.read();}); 中调用read() 并首先定义数据源本身

    我猜最后一点是最关键的;)

    这就是我所做的一切,所以如果它不能以这种方式工作,那么数据格式本身或模板定义中可能会出现一些错误。有什么控制台错误之类的吗?

    干杯

  • 【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-16
      • 2013-05-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多