0

我有一个 KendoUI 数据源

 var myDS = new kendo.data.DataSource({
        transport: {
            read:
            {
                url: getData,
                contentType: 'application/json; charset=utf-8',

            },
            destroy:
            {

                url: deleteData,
                contentType: 'application/json; charset=utf-8',


            },
            parameterMap: function(options, operation) {
                if (operation !== "destroy" && options.models) {
                    return { models: kendo.stringify(options.models) };
                }

            }
        },
        schema: {
            model: {
                id: "Id",
                fields: {
                    Id: { editable: false, nullable: true },
                   name: { type: "string" }

                }
            }
        }

    });

我将数据源绑定到 Kendo ListView 如下

  var listView = $("#alistview").kendoListView({
        dataSource: myDS ,
        template: kendo.template($("#template").html())
    }).data("kendoListView");;

我创建了 ListView 和小部件,如下所示,

  <div id="alistview" style="margin-top:30px"></div>

        <script type="text/x-kendo-tmpl" id="template">
            <div>

                <div>
                    #:name#
                    <a class="k-button k-button-icontext k-delete-button" href="\\#"><span      class="k-icon k-delete"></span></a>

                </div>

            </div>
        </script>
    </div>

在删除按钮上单击正在调用 KendoUI 数据源的销毁对象。我的问题是如何在数据源的销毁对象中获取 ListView 的选定项。例如,当用户单击删除按钮时,我想读取所选项目的名称。

有什么帮助吗?

4

1 回答 1

0

I got the answer. We can use function in the url instead of the object and inside the function selected item which is calling the destroy can be fetched as follows:

  var myDS= new kendo.data.DataSource({
        transport: {
            read:
            {
                url: getdata,
                contentType: 'application/json; charset=utf-8',

            },
            destroy:
            {
                url: function (appt) { return deteletedata+ "?accountid=" + appt.Id },
                contentType: 'application/json; charset=utf-8',
                //data: {

                //    AccountId: "3"
                //}

            },
            parameterMap: function(options, operation) {
                if (operation !== "destroy" && options.models) {
                    return { models: kendo.stringify(options.models) };
                }

            }
        },
        schema: {
            model: {
                id: "Id",
                fields: {
                    Id: { editable: false, nullable: true },
                    accountname: { type: "string" }

                }
            }
        }

    });
于 2014-11-25T02:34:55.910 回答