是否可以通过点击一行,按下 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/