未选择的 Flask-Admin 自定义操作
Flask-Admin custom action with unselected
我们可以使用 @action
装饰器来处理未选择的元素吗?
当我们使用
@action
def action_custom(self, ids):
ids
= 页面上选中的元素,但我们可以在这里获取未选中的元素吗?
您可以在 Flask-Admin 中破解 action.js 并更改提交表单以将未选中的行作为隐藏值包含在内,然后您可以使用提交的 python @action 方法获取这些值表单的 getlist 方法。
在 action.js 的第 21 行,我们有:
$('input.action-checkbox', form).remove();
$('input.action-checkbox:checked').each(function() {
form.append($(this).clone());
});
form.submit();
更改此设置,使未选中的行包含在表单中。请注意 jQuery 选择器中 :not(:checked)
的使用,并将值保存到名为 'notrowid'
:
的隐藏输入中
$('input.action-checkbox', form).remove();
$('input.action-checkbox:not(:checked)').each(function(i, v) {
form.append($('<input>').attr({'type':'hidden', 'name':'notrowid', 'value': v.value}));
});
$('input.action-checkbox:checked').each(function() {
form.append($(this).clone());
});
form.submit();
现在,在您的 python (Python 2) @action
方法中,您可以执行以下操作:
@action
def action_custom(self, ids):
_not_selected_ids = request.form.getlist('notrowid')
print _not_selected_ids
我们可以使用 @action
装饰器来处理未选择的元素吗?
当我们使用
@action
def action_custom(self, ids):
ids
= 页面上选中的元素,但我们可以在这里获取未选中的元素吗?
您可以在 Flask-Admin 中破解 action.js 并更改提交表单以将未选中的行作为隐藏值包含在内,然后您可以使用提交的 python @action 方法获取这些值表单的 getlist 方法。
在 action.js 的第 21 行,我们有:
$('input.action-checkbox', form).remove();
$('input.action-checkbox:checked').each(function() {
form.append($(this).clone());
});
form.submit();
更改此设置,使未选中的行包含在表单中。请注意 jQuery 选择器中 :not(:checked)
的使用,并将值保存到名为 'notrowid'
:
$('input.action-checkbox', form).remove();
$('input.action-checkbox:not(:checked)').each(function(i, v) {
form.append($('<input>').attr({'type':'hidden', 'name':'notrowid', 'value': v.value}));
});
$('input.action-checkbox:checked').each(function() {
form.append($(this).clone());
});
form.submit();
现在,在您的 python (Python 2) @action
方法中,您可以执行以下操作:
@action
def action_custom(self, ids):
_not_selected_ids = request.form.getlist('notrowid')
print _not_selected_ids