制作按钮在CJuiDialog中不可见
问题描述:
我在我的CJuiDialog中遇到了问题。我想将“删除”按钮设置为“不可见”,但这不起作用,该按钮仍然显示。 这里是我的代码:制作按钮在CJuiDialog中不可见
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'dlg_EventCal',
'options' => array(
'title' => Yii::t('CalModule.fullCal', 'Event detail'),
'modal' => true,
'autoOpen' => false,
'hide' => 'slide',
'show' => 'slide',
'width'=> 400,
'buttons' => array(
array(
'text' => Yii::t('CalModule.fullCal', 'OK'),
'click' => "js:function() { eventDialogOK(); }"
),
array(
'text' => Yii::t('CalModule.fullCal', 'Cancel'),
'click' => 'js:function() { $(this).dialog("close"); }',
),
array(
'text' => Yii::t('CalModule.fullCal', 'Delete'),
'click' => 'js:function() { eventDialogDelete(); }',
'visible'=>Yii::app()->user->checkAccess('deleteAllEvents'),
),
))));
答
CJuiDialog
只有
看看这个功能将数据传递到jQuery.dialog
插件(从https://github.com/jquery/jquery-ui/blob/master/ui/jquery.ui.dialog.js#L322):
_createButtons: function(buttons) {
var that = this,
hasButtons = false;
// if we already have a button pane, remove it
this.uiDialogButtonPane.remove();
this.uiButtonSet.empty();
if (typeof buttons === "object" && buttons !== null) {
$.each(buttons, function() {
return !(hasButtons = true);
});
}
if (hasButtons) {
$.each(buttons, function(name, props) {
var button, click;
props = $.isFunction(props) ?
{ click: props, text: name } :
props;
// Default to a non-submitting button
props = $.extend({ type: "button" }, props);
// Change the context for the click callback to be the main element
click = props.click;
props.click = function() {
click.apply(that.element[0], arguments);
};
button = $("<button></button>", props)
.appendTo(that.uiButtonSet);
if ($.fn.button) {
button.button();
}
});
this.uiDialog.addClass("ui-dialog-buttons");
this.uiDialogButtonPane.appendTo(this.uiDialog);
} else {
this.uiDialog.removeClass("ui-dialog-buttons");
}
}
你的所有属性都会被传递到props
对象,之后将用作button
元素的属性:
button = $("<button></button>", props)
因此,你需要这样的代码:
array(
'text' => Yii::t('CalModule.fullCal', 'Delete'),
'click' => 'js:function() { eventDialogDelete(); }',
'style' => Yii::app()->user->checkAccess('deleteAllEvents') ? '' : 'display: none;',
)
但在这种情况下,你所需要的权限的其他检查服务器端!
非常感谢,它是真正有用的,其作品:-) – user1805577