起初她工作完美,但我添加了一个javascript函数:当我取消选中项目时,她将被删除,问题是: 当我添加项目时,总是所有项目都显示在我的弹出窗口小部件中,我如何删除存在项目或其他解决方案表明项目已被选中? 打印在屏幕下方和js代码:
(function($) {
Drupal.behaviors.entityreferenceViewWidget = {
attach: function(context, settings) {
var checkboxes = '#modal-content input.entity-reference-view-widget-select';
var selectAllSelector = '#entityreference-view-widget-select-all';
$(selectAllSelector).unbind('click').data('unselect', 0).click(function() {
if ($(this).data('unselect')) {
$(checkboxes).removeAttr('checked');
$(this).data('unselect', 0).text(Drupal.t('Select all'));
}
else {
$(checkboxes).attr('checked', 'checked');
$(this).data('unselect', 1).text(Drupal.t('Unselect all'));
}
return false;
});
if (settings.entityReferenceViewWidget) {
var ervwSetttings = settings.entityReferenceViewWidget.settings;
if (ervwSetttings.cardinality != -1 || $(checkboxes).length === 0) {
$(selectAllSelector).remove();
}
var selector = '#' + ervwSetttings.table_id + ' input[type=checkbox]:checked';
var selected_ids = '';
$(selector).each(function() {
selected_ids += $(this).val() + ';';
});
if (selected_ids.length > 0) {
$('input[name="selected_entity_ids"]').val(selected_ids.substring(0, selected_ids.length - 1)).trigger('change');
}
// We need to pass the settings via an hidden field because Views doesn't
// allow us to pass data between ajax requests.
if (settings.entityReferenceViewWidget.serialized) {
$('input[name="ervw_settings"]').val(settings.entityReferenceViewWidget.serialized);
}
}
$('.field-widget-entityreference-view-widget input[type=checkbox]:checked').each(function() {
$(this).onclick = function() {
console.log(1)
}
$(this).addClass('uncheck-to-remove').attr('title',Drupal.t('Uncheck to remove this item')).click(function() {
$(this).closest('tr').hide(500);
});
});
}
// }
};
// Create a new ajax command, ervw_draggable that is called to make the rows
// of the widget draggable.
Drupal.ajax.prototype.commands.ervw_draggable = function(ajax, response, status) {
$('#' + response.selector + ' tr').each(function(){
var el = $(this);
Drupal.tableDrag[response.selector].makeDraggable(el.get(0));
el.find('td:last').addClass('tabledrag-hide');
if ($.cookie('Drupal.tableDrag.showWeight') == 1) {
el.find('.tabledrag-handle').hide();
}
else {
el.find('td:last').hide();
}
});
};
})(jQuery);
答案 0 :(得分:0)
您不必为此编写任何代码(隐藏部分必须使用js代码atm编写),这只是配置。
要不显示已在您创建的视图中添加的模态中已选择的项目,您必须在节点的nid上有一个上下文过滤器。编辑此上下文过滤器并检查"排除"在"更多"菜单(添加多个值旁边)。
查看此视频:http://codekarate.com/daily-dose-of-drupal/entity-reference-view-widget,时间为8:00。该视频解释了此小部件的几乎所有基本配置。