kendo DataSource

1.transport

标准的DataSource格式,默认get请求:

var dataSource = new kendo.data.DataSource({
  transport: {
    read:  {
      url: "https://demos.telerik.com/kendo-ui/service/products",
      dataType: "jsonp" 
    },
    update: {
      url: "https://demos.telerik.com/kendo-ui/service/products/update",
      dataType: "jsonp"  
    }
  }
});

设置为post请求:

var dataSource = new kendo.data.DataSource({
  transport: {
    update: {
      type: "POST"
    }
  }
});

自己写ajax请求:

注意:如果transport中有一个方法是自己写的ajax请求,则其他方法也需要使用自己写的ajax请求,需保持一致。

var dataSource = new kendo.data.DataSource({
  transport: {
    read: function(options) {
    },
    update: function(options) {
      $.ajax({
        url: "https://demos.telerik.com/kendo-ui/service/products/update",
        dataType: "jsonp", 
        data: {
          models: kendo.stringify(options.data.models)
        },
        success: function(result) {
          options.success(result);
        },
        error: function(result) {
          options.error(result);
        }
      });
    }
  }
});

需要传递的其他参数data:

//作为对象发送
var dataSource = new kendo.data.DataSource({
  transport: {
    update: {
      cache: true,    //是否缓存请求结果
      contentType: "application/json",  //发送到服务器的内容表头
      dataType: "json",    //发送服务器的数据类型
      data: {
        name: "Jane Doe",
        age: 30
      }
    }
  }
})
//从函数返回发送其他参数
var dataSource = new kendo.data.DataSource({
  transport: {
    update: {
      data: function() {
        return {
          name: "Jane Doe",
          age: 30
        }
      }
    }
  }
});

2.schema

猜你喜欢

转载自www.cnblogs.com/zsj-02-14/p/9353092.html