Kendo ui 如何在kendo UI数据源中编写动态URL,如;更新/{id}";

Kendo ui 如何在kendo UI数据源中编写动态URL,如;更新/{id}";,kendo-ui,kendo-grid,kendo-datasource,Kendo Ui,Kendo Grid,Kendo Datasource,我有一个web API。在这篇文章中,我编写了一个更新方法。但它需要表行的id才能更新到该行。 我使用网格显示数据,并使用工具栏编辑行。 我的问题是如何将该id传递给更新。 有人能指导我吗?好吧,我建议你,多解释一下你的问题,但我认为如果你有这样一个工具栏作为模板,这个例子可能会有所帮助: <script type="text/x-kendo-template" id="template"> <div class="toolbar">

我有一个web API。在这篇文章中,我编写了一个更新方法。但它需要表行的id才能更新到该行。 我使用网格显示数据,并使用工具栏编辑行。 我的问题是如何将该id传递给更新。
有人能指导我吗?

好吧,我建议你,多解释一下你的问题,但我认为如果你有这样一个工具栏作为模板,这个例子可能会有所帮助:

  <script type="text/x-kendo-template" id="template">
            <div class="toolbar">
             <button type="button" id="update">Update</button>

            </div>
  </script>
并在ajax中发送行id,但如果要使用内联版本更新行,可以尝试使用如下数据源

        dataSource = new kendo.data.DataSource({
            transport: {
                read: function(options) {
                    $.ajax( {
                        url: "readUsuarios",
                        dataType: "json",
                        success: function(result) {
                            options.success(result);
                        }
                    });

                },
                update: function(options) {

                    $.ajax( {
                        url: "updateUsuarios",
                        dataType: "json",
                        data: {
                            models: kendo.stringify(options.data.models)
                        },
                        success: function(data) {

                               // response server; 

                        },
                        error: function(result) {
                            // notify the data source that the request failed
                            options.error(result);
                        }
                    });
                }
            },
            batch: true,
            pageSize: 20,
            schema: {
                model: {
                    id: "id",
                    fields: {

                        username: { editable: false, nullable: true },
                        nombre: { validation: { required: true } },
                        apellido: { type: "string", validation: { required: true} },
                        ci: { type: "string", validation: { required: true} },
                        email: { type: "string", validation: { required: true } },
                        activo: { type: "boolean",editable: false },
                        fecha_caducidad: { type: "date" },
                        licencia_status:{editable: false} 

                    }
                }
            }
        });
我希望这有帮助

更新:功能(选项){


请发布您的数据源代码,以便我们可以为您提供帮助。我发现了类似的情况。您能再解释一下吗。我不知道如何传递数据进行更新。'update:{url:function(item){return'update/'+item.id;}}'在这里,我应该从哪里传递这个'项目'。好的,当你在url中发送参数时,这就起作用了,选择发送参数的方式取决于服务器端,如果你有一个web服务类型GET,你可以在url中发送参数,在你建议的代码中,url函数访问编辑的项目是一个参数,接收本机不需要传递任何内容,这是自动的,因此您可以获取该行的属性
 $("#update").kendoButton({
        click: function(){

           //Here you will have the selected row

            var self=$('#grid').data('kendoGrid')
            var index = self.items().index(self.select());
            var rowActual= self.dataSource.data()[index];
            rowActual=self.dataItem(self.select()); 


            if(rowActual==undefined || rowActual ==null) {

                alert("No row selected");


            }else{
                  $.ajax({
                            type: "POST",
                            url: "update",
                            data: {
                                id:rowActual.id
                            },

                            dataType: 'json',
                            success: function (data) {          


                            },
                            error: function(){                                  

                            }
                        });
            }

        }
    });
        dataSource = new kendo.data.DataSource({
            transport: {
                read: function(options) {
                    $.ajax( {
                        url: "readUsuarios",
                        dataType: "json",
                        success: function(result) {
                            options.success(result);
                        }
                    });

                },
                update: function(options) {

                    $.ajax( {
                        url: "updateUsuarios",
                        dataType: "json",
                        data: {
                            models: kendo.stringify(options.data.models)
                        },
                        success: function(data) {

                               // response server; 

                        },
                        error: function(result) {
                            // notify the data source that the request failed
                            options.error(result);
                        }
                    });
                }
            },
            batch: true,
            pageSize: 20,
            schema: {
                model: {
                    id: "id",
                    fields: {

                        username: { editable: false, nullable: true },
                        nombre: { validation: { required: true } },
                        apellido: { type: "string", validation: { required: true} },
                        ci: { type: "string", validation: { required: true} },
                        email: { type: "string", validation: { required: true } },
                        activo: { type: "boolean",editable: false },
                        fecha_caducidad: { type: "date" },
                        licencia_status:{editable: false} 

                    }
                }
            }
        });
                $.ajax( {
                    url: function(data) { return "updateUsuarios/"+data.Id,
                    dataType: "json",
                   .....