单击组合 box:Yii 1.1 在 texteditor tinymce 中显示值
Display value in texteditor tinymce on click of combo box:Yii 1.1
我必须在我的表单中使用文本编辑器,即 tinymce。我必须在文本编辑器中显示数据以选择组合 box.Simply 使用 textarea 没有问题我可以在我的文本区域中获得选择的价值combo.Now 我必须使用文本编辑器而不是简单的文本区域。
我的查看代码是:
<div class="row col2">
<?php echo $form->labelEx($model,'template'); ?>
<?php
$records = CHtml::listData(EmailTemplate::model()->findAll(array('order' => 'email_template_id','condition'=>"status= '1'")), 'email_template_id', 'subject');
// echo $form->dropDownList($model,'template',$records,array('id'=>'myDropDown','empty' => 'Select'));
echo $form->dropDownList($model,'template',$records,array(
'id' => 'myDropDown',
'empty' => 'Select Template',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('reply/description'),//your controller and action name
'update'=>'#myTextArea',
'success'=> 'function(data) {
$("#myTextArea").empty();
$("#myTextArea").val(data);
} '
)));
?>
<?php echo $form->error($model,'template'); ?>
</div>
<div class="row col2">
<?php echo $form->labelEx($model,'message'); ?>
<?php echo $form->textArea($model,'message',array('id'=>'myTextArea','style'=>'width: 680px; height: 300px;')); ?>
<?php echo $form->error($model,'message'); ?>
</div>
我的js代码如下:
<script type="text/javascript">
tinymce.init({
selector: "textarea#myTextArea",
theme: "modern",
preformatted:true,
width: 700,
height: 300,
plugins: [
"advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality emoticons template paste textcolor"
],
content_css: "css/content.css",
menubar:false,
toolbar: "bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent| forecolor backcolor",
});
</script>
<script>
$('#myDropDown').on('change', function() {
$.ajax({
url: "<?php echo $this->createUrl('reply/description'); ?>",
dataType: 'html',
type: 'POST',
data: {dropDownValue: $(this).val()},
success: function(template, textStatus, jqXHR) {
alert(data);
$('#myTextArea').val(data);
}
});
});
</script>
我的控制器是:
public function actionDescription()
{
$cvId=0;
$cvId= $_POST['Reply']['template'];
if (Yii::app()->request->isAjaxRequest) {
if($cvId>0){
$templateModel=EmailTemplate::model()->findByPk($cvId);
echo $templateModel->description;
}
}
}
一旦 TinyMCE 出现在页面上,只需更改基础文本区域的内容(您在 AJAX 调用中所做的)不会导致 TinyMCE 重新加载内容。
您需要使用 TinyMCE 的 API 在 AJAX 调用的成功方法中设置编辑器的内容。
例如:
tinyMCE.activeEditor.setContent(data);
...其中数据是一个字符串,其中包含您的 AJAX 调用返回的内容。
好的,我发现我的 question.simple 更改的答案是在下拉列表 code.It 中进行的,现在效果很好。
<?php
$records = CHtml::listData(EmailTemplate::model()->findAll(array('order' => 'email_template_id','condition'=>"status= '1'")), 'email_template_id', 'subject');
echo $form->dropDownList($model,'template',$records,array(
'id' => 'myDropDown',
'empty' => 'Select Template',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('marketingEmail/description'),
'update'=>'#myTextArea',
'success'=> 'function(data) {
$("#myTextArea").empty();
tinyMCE.activeEditor.setContent(data);
} '
)));
?>
我必须在我的表单中使用文本编辑器,即 tinymce。我必须在文本编辑器中显示数据以选择组合 box.Simply 使用 textarea 没有问题我可以在我的文本区域中获得选择的价值combo.Now 我必须使用文本编辑器而不是简单的文本区域。 我的查看代码是:
<div class="row col2">
<?php echo $form->labelEx($model,'template'); ?>
<?php
$records = CHtml::listData(EmailTemplate::model()->findAll(array('order' => 'email_template_id','condition'=>"status= '1'")), 'email_template_id', 'subject');
// echo $form->dropDownList($model,'template',$records,array('id'=>'myDropDown','empty' => 'Select'));
echo $form->dropDownList($model,'template',$records,array(
'id' => 'myDropDown',
'empty' => 'Select Template',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('reply/description'),//your controller and action name
'update'=>'#myTextArea',
'success'=> 'function(data) {
$("#myTextArea").empty();
$("#myTextArea").val(data);
} '
)));
?>
<?php echo $form->error($model,'template'); ?>
</div>
<div class="row col2">
<?php echo $form->labelEx($model,'message'); ?>
<?php echo $form->textArea($model,'message',array('id'=>'myTextArea','style'=>'width: 680px; height: 300px;')); ?>
<?php echo $form->error($model,'message'); ?>
</div>
我的js代码如下:
<script type="text/javascript">
tinymce.init({
selector: "textarea#myTextArea",
theme: "modern",
preformatted:true,
width: 700,
height: 300,
plugins: [
"advlist autolink link image lists charmap print preview hr anchor pagebreak spellchecker",
"searchreplace wordcount visualblocks visualchars code fullscreen insertdatetime media nonbreaking",
"save table contextmenu directionality emoticons template paste textcolor"
],
content_css: "css/content.css",
menubar:false,
toolbar: "bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent| forecolor backcolor",
});
</script>
<script>
$('#myDropDown').on('change', function() {
$.ajax({
url: "<?php echo $this->createUrl('reply/description'); ?>",
dataType: 'html',
type: 'POST',
data: {dropDownValue: $(this).val()},
success: function(template, textStatus, jqXHR) {
alert(data);
$('#myTextArea').val(data);
}
});
});
</script>
我的控制器是:
public function actionDescription()
{
$cvId=0;
$cvId= $_POST['Reply']['template'];
if (Yii::app()->request->isAjaxRequest) {
if($cvId>0){
$templateModel=EmailTemplate::model()->findByPk($cvId);
echo $templateModel->description;
}
}
}
一旦 TinyMCE 出现在页面上,只需更改基础文本区域的内容(您在 AJAX 调用中所做的)不会导致 TinyMCE 重新加载内容。
您需要使用 TinyMCE 的 API 在 AJAX 调用的成功方法中设置编辑器的内容。
例如:
tinyMCE.activeEditor.setContent(data);
...其中数据是一个字符串,其中包含您的 AJAX 调用返回的内容。
好的,我发现我的 question.simple 更改的答案是在下拉列表 code.It 中进行的,现在效果很好。
<?php
$records = CHtml::listData(EmailTemplate::model()->findAll(array('order' => 'email_template_id','condition'=>"status= '1'")), 'email_template_id', 'subject');
echo $form->dropDownList($model,'template',$records,array(
'id' => 'myDropDown',
'empty' => 'Select Template',
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('marketingEmail/description'),
'update'=>'#myTextArea',
'success'=> 'function(data) {
$("#myTextArea").empty();
tinyMCE.activeEditor.setContent(data);
} '
)));
?>