2

Kendo ui 网格我在网格上附加了更改事件,但是每次单击一行时它都会发出两次警报。

function onChange(arg) {
    var selected = $.map(this.select(), function (item) {
        return $(item).text();
    });
    alert(selected.join(", "));
}

网格代码

@(Html.Kendo().Grid<ETender.Mvc.Models.Region>()
                .Name("country")
                    .Columns(columns =>
                    {
                        columns.Bound(r => r.ID);
                        columns.Bound(r => r.CNAME);
                        columns.Bound(r => r.ENAME);
                    })
                    .Sortable()
                    //.Scrollable(scrollable => scrollable.Virtual(false).Height(500))
                    .Selectable()
                    .Pageable()
                    .Reorderable(reorder => reorder.Columns(true))
                    .Resizable(resize => resize.Columns(true)) 
                    .DataSource(dataSource => dataSource
                        .Ajax()
                        .ServerOperation(true)
                        .Events(ev => ev.Error("loadError"))
                        .Model(m =>
                        {
                            m.Id(p => p.ID);
                            m.Field(p => p.ID).Editable(false);
                        })
                        .Read(read => read.Action("GetRegionList", "Region")
                            .Data("function() { return {         CountryID:'0',ProvinceID:'0',CityID:'0',RegionType: 'Country'}; }")
                            )
                    )
                     .Events(events => events.Change("onChange"))

                )

谁有解决办法。

4

1 回答 1

2

Basically this behavior is caused by using "alert" method for debugging purposes - please note that this is not recommended because it can lead to unexpected behavior when interacting with focusing elements. After replacing the "alert" method and with "debugger" command or "console.log()" function the change event will work as expected.

于 2013-04-27T14:32:35.540 回答