javascript - Wicket:选择多行(Shift-单击)

标签 javascript java html wicket

是否可以通过点击一行,按下 shift 键然后点击另一行来选择 Wicket 中的多行?

我正在使用 Wicket 6.20。我已经找到了选择单行的代码,但我不确定如何添加 AJAX 事件来确定用户是否按下了 shift 键。

@Override
protected Item<T> newRowItem(final String id, final int index, final IModel<T> model) {
    final Item<T> rowItem = new OddEvenItem<>(id, index, model);
    rowItem.add(new AjaxEventBehavior("onclick") {

        private static final long serialVersionUID = 6720512493017210281L;

        @Override
        protected void onEvent(AjaxRequestTarget target) {

            SearchResultsRow row = (SearchResultsRow) rowItem.getModelObject();
            row.setSelected(!row.isSelected());

            parent.updateSearchResults(target);
        }
    });
    return rowItem;
}

最佳答案

我将此代码段用于 shift/ctrl ajax-click:

public class AjaxClickWithKeysBehavior extends AjaxEventBehavior
{

    public AjaxClickWithKeysBehavior()
    {
        super( "click" );
    }

    @Override
    protected void updateAjaxAttributes( AjaxRequestAttributes attributes )
    {
        super.updateAjaxAttributes( attributes );

        attributes.getDynamicExtraParameters().add( "return {'ctrl' : attrs.event.ctrlKey, 'shift' : attrs.event.shiftKey}" );
    }

    @Override
    protected void onEvent( AjaxRequestTarget target )
    {
        final RequestCycle requestCycle = RequestCycle.get();

        boolean isCtrl = requestCycle.getRequest().getRequestParameters().getParameterValue( "ctrl" ).toBoolean( false );
        boolean isShift = requestCycle.getRequest().getRequestParameters().getParameterValue( "shift" ).toBoolean( false );

        this.onClick( target, isCtrl, isShift );
    }

    protected void onClick( AjaxRequestTarget target, boolean isCtrl, boolean isShift )
    {
    }

}

关于javascript - Wicket:选择多行(Shift-单击),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34887713/

相关文章:

javascript - 如何为以字符串为键、以 React SFC 作为值的对象包装器定义 TypeScript 类型?

javascript - navigator.geolocation.getCurrentPosition 有时有效 有时无效

Java: "Unexpected Type; required: Variable; found: value"通过尝试返回一个值

html - 很难为横向和纵向图片自动调整背景面板的大小。

html - 从路径字符串构建分层列表的最佳方法

javascript - 背景颜色从下到上悬停动画

javascript - Props 返回未定义,但我可以在控制台中看到它的值

java - 在 rcon 客户端上显示来自游戏服务器的控制台源

java - eclipse 警告 : Type safety (Java Generics)

php - 从 mysql 打印的每一行都应该是彩色的