如何在Kendo UI DataSource Destroy中查找选定的ListView项目

时间:2014-11-24 20:56:25

标签: kendo-ui kendo-datasource kendo-listview

我有一个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和widget,如下所示,

  <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 DataSource的destroy对象。我的问题是如何在数据源的destroy对象中获取ListView的选定项。例如,当用户单击删除按钮时,我想要读取所选项的名称。

任何帮助?

1 个答案:

答案 0 :(得分:0)

我得到了答案。我们可以使用url中的函数而不是对象,并且在函数内部可以获取调用destroy的项目,如下所示:

  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" }

                }
            }
        }

    });