twitter-bootstrap-3 - Yii2:HTML 不会使用 Tooltip 呈现
问题描述
提示:已插入 Pastebin 链接,如我上一条评论中所示
提示:穆罕默德的解决方案仍然不起作用(参见新工具提示的图片)!
我的布局文件编码如下:
<?php
use yii\helpers\Html;
use common\wsl_components\AdminLteAsset;
$js = <<<SCRIPT
$(function () {
$('body').tooltip({
selector: '[data-toggle="tooltip"]',
html:true
});
});
SCRIPT;
// Register tooltip/popover initialization javascript
$this->registerJs($js);
AdminLteAsset::register($this);
$this->beginPage()
?>
<!DOCTYPE html>
<html lang="<?= Yii::$app->language ?>">
<head>
<meta charset="<?= Yii::$app->charset ?>"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<?= Html::csrfMetaTags() ?>
<title><?= Html::encode($this->title) ?></title>
<?php $this->head(); ?>
</head>
<body class="hold-transition skin-blue sidebar-mini sidebar-collapse">
<?php $this->beginBody(); ?>
<div class="wrapper">
<?=
$this->render(
'header.php'
);
?>
<?=
$this->render(
'left.php'
);
?>
<?=
$this->render(
'content.php', ['content' => $content]
);
?>
</div>
<?php $this->endBody(); ?>
</body>
</html>
<?php $this->endPage(); ?>
我GridView
的编码是这样的:
[
'attribute' => $dummy ,
'label' => Yii::t ( 'app' , 'Charakterisierung' ) ,
'format' => 'html' ,
'value' => function($model) {
if ( !empty ( $model->person->personentypDominant->typ_name )) {
$tag = Html::tag ( 'span' , 'Tooltip-Touch Me!' , [
// html-tags won't be rendered in title
'title' => $model->person->personentypDominant->typ_empfehlung ,
'data-placement' => 'left' ,
'data-toggle'=>'tooltip',
'style' => 'white-space:pre;border:1px solid red;'
] );
return $tag . "<br>" . $model->person->personentypDominant->typ_verhaltensmerkmal_im_team_1 . "," . $model->person->personentypDominant->typ_verhaltensmerkmal_bei_stress_3 . "," . $model->person->personentypDominant->typ_verhaltensmerkmal_am_arbeitsplatz_4;
}
}
],
尽管如此,Tooltip 中的 HTML-Tags 不会被渲染。它们出现在数据库中,例如:
Verhaltensempfehlung:<br><ul><li>
Kompetenz und Selbstbewusstsein zeigen,</ul></li>
我不知道为什么,但不会解释上面的标签。它们在工具提示中硬编码。任何想法,我做错了什么?
编辑:穆罕默德已经回答了我的问题,但答案并没有解决我的问题!为了显示我的问题,请看附件!
解决方案
你显然有2个错误
在
view
您提供的行149
中,您缺少data-toggle="tooltip"
跨度上的属性。将它们更改为
$tag_rot = Html::tag( 'span', 'Typ Rot', [ 'title' => $tooltip_rot, 'data-toggle' => 'tooltip', 'data-placement' => 'left', 'style' => 'white-space:pre;border:2px solid red;' ] ); $tooltip_green = \common\modules\lookup\models\LPersonentyp::findOne(2)->typ_empfehlung; $tag_green = Html::tag( 'span', 'Typ Grün', [ 'title' => $tooltip_green, 'data-toggle' => 'tooltip', 'data-placement' => 'left', 'style' => 'white-space:pre;border:2px solid green;' ] ); $tooltip_blue = \common\modules\lookup\models\LPersonentyp::findOne(3)->typ_empfehlung; $tag_blue = Html::tag( 'span', 'Typ Blau', [ 'title' => $tooltip_blue, 'data-toggle' => 'tooltip', 'data-placement' => 'left', 'style' => 'white-space:pre;border:2px solid blue;' ] );
在您正在使用的 Gridview 列中,
"format"=>"html"
而您应该使用"format"=>"raw"
将列定义更改为以下
[ 'attribute' => $dummy , 'label' => Yii::t ( 'app' , 'Charakterisierung' ) , 'format' => 'raw' , 'value' => function($model) { if ( !empty ( $model->person->personentypDominant->typ_name ) ) { $tag = Html::tag ( 'span' , 'Tooltip-Touch Me!' , [ 'title' => $model->person->personentypDominant->typ_empfehlung , 'data-placement' => 'left' , 'data-toggle' => 'tooltip' , 'style' => 'white-space:pre;border:1px solid red;' ] ); return $tag . "<br>" . $model->person->personentypDominant->typ_verhaltensmerkmal_im_team_1 . "," . $model->person->personentypDominant->typ_verhaltensmerkmal_bei_stress_3 . "," . $model->person->personentypDominant->typ_verhaltensmerkmal_am_arbeitsplatz_4; } } ] ,
我之前给出的ANSWER
更侧重于工具提示的使用,html::tag()
并且我使用您的 gridview 列的代码来复制粘贴,并且忘记在 gridview 内部使用的情况下提及它,我也更新了该答案。
推荐阅读
- python - pandas:df.apply() 使用 df.groupby() 进行幕后计算
- magento - Magmi 根类别创建
- checkbox - 角度 5 反应形式复选框发送对象
- vba - 在 Excel VBA 中插入数组公式
- python - 如何在 pandas 系列列表中使用 OneHotEncoder?
- email - 在 Rhat 上使用 base64 编码的电子邮件附件
- sql - 从访问表单插入到表中
- trackjs - 如何向 TrackJS 添加自定义日志记录
- python - 如何爬取 href - Python & beautifulsoup
- c# - Hangfire 服务器正在尝试处理来自其他队列的作业