【问题标题】:Simple Kendo UI remote DataSource returns empty简单的 Kendo UI 远程数据源返回空
【发布时间】:2013-03-05 05:04:31
【问题描述】:

这是我尝试构建的一个简单示例作为练习,我的 DataSource 对象返回时没有数据。

var data = new kendo.data.DataSource({
            transport: {
                read: {
                    url: "data.json",
                    dataType: "json"
                }
            }
        });

        console.dir( data );

数据.json

[
    {
        "text": "Brand One"
    },
    {
        "text": "Brand Two"
    },
    {
        "text": "Brand Three"
    },
    {
        "text": "Brand Four"
    }
]

有什么想法吗?

【问题讨论】:

    标签: javascript json kendo-ui


    【解决方案1】:

    您的代码有两个问题

    1. 首先您需要调用 data.read() - 这样请求才会被执行
    2. 由于上述操作是异步操作,如果您在使用 data.read() 后立即调用,则调用 data.data() 不会返回任何内容。要等到检索到数据,您需要使用requestEnd 事件。

    【讨论】:

      【解决方案2】:

      我可以将加载数组加载到数据源并返回对象,请参阅

      var data_input= [
          {
              "text": "Brand One"
          },
          {
              "text": "Brand Two"
          },
          {
              "text": "Brand Three"
          },
          {
              "text": "Brand Four"
          }
      ];
      
      var data = new kendo.data.DataSource({
                  transport: {
                      read: {
                          data: data_input,
                          dataType: "json"
                      }
                  }
              });
      
      console.log(data)
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-12
      • 2014-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多