How to use URLs like '/update/:id' as KendoUI datasource?

不想你离开。 提交于 2019-12-23 18:04:25

问题


I read the documentation but found nothing related to setting parameters in dataSource urls. Is it possible to achieve that?

Thx in advance.


回答1:


Yes, it is possible. The urls defined in the DataSource.transport might be a function. This function receives (for update) as first argument the data being updated (the model) and returns the string that should be used as URL.

Composing the URL for what you want to do is:

var ds = new kendo.data.DataSource({
    transport: {
        read: {
            url: function () {
                return 'read';
            }
        },
        update: {
            url : function (item) {
                return 'update/' + item.id;
            }
        }
    }
});



回答2:


Short answer:

Nope.

Long answer:

Parameters are passed either inline with the url parameter of the transport object...

var id = 'abc123';

var ds = new kendo.data.DataSource({
  transport: {
    read: {
      url: 'api/employees?id=' + id
    }
  }
});

...or they are passed in the data parameter of the transport object.

var id = 'abc123';

var ds = new kendo.data.DataSource({
  transport: {
    read: {
      url: 'api/employees',
      data: {
        id: id;
      }
    }
  }
});

or

var id = 'abc123';

var ds = new kendo.data.DataSource({
  transport: {
    read: {
      url: 'api/employees',
      data: function () {
        return { id : id };
      }
    }
  }
});


来源:https://stackoverflow.com/questions/25554255/how-to-use-urls-like-update-id-as-kendoui-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!