【问题标题】:How to find selected ListView Item in Kendo UI DataASource Destroy如何在 Kendo UI DataASource Destroy 中找到选定的 ListView 项目
【发布时间】:2023-03-29 02:46:01
【问题描述】:

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

有什么帮助吗?

【问题讨论】:

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


    【解决方案1】:

    我得到了答案。我们可以在 url 中使用函数而不是对象,并且在函数中调用销毁的选定项可以按如下方式获取:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-03
      • 1970-01-01
      相关资源
      最近更新 更多