在文本编辑器中显示值,点击组合框:Yii 1.1.
Display value in texteditor tinymce on click of combo box:Yii 1.1
我必须使用文本编辑器,即在我的表单中使用tinymce。我必须在选择组合框的文本编辑器中显示数据。简单地使用文本区域没有问题,我可以在选择组合时在我的文本区域获得价值。现在我必须使用文本编辑器而不是简单的文本区域。我的视图代码是:
<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 调用返回的内容的字符串。
好的,
我想出了问题的答案。下拉列表代码进行了简单的更改。它现在运行良好。
<?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);
} '
)));
?>
相关文章:
- 根据id将json数组组合为一个json数组
- 接受不在列表中的值-引导组合框
- 如何解决Yii中的页面刷新问题
- 从客户端获取修改后的对象,并将其与服务器上的原始对象组合
- 组合两个javascript函数
- Telerik rad组合框多列数据绑定
- 组合 2 个 JavaScript .scroll 函数
- 如何使用jquery组合两个数组
- onChange不足以从Dojo组合框触发查询
- 组合承诺和非承诺值
- 所有控件的组合框
- 在D3中组合多个事件
- 如何在yii中使用append
- AngularJS-如何只对多个事件的组合采取行动
- 如何在服务、技能、投资组合等方面添加滑动效果
- 以编程方式填充组合框道场 (1.8) 的最佳方法是什么?
- 如何在谷歌可视化中组合数字和模式格式化程序
- 更改组合框分页后,getValue和getRawValue返回相同的值
- 类型错误:url未定义extjs 4正在填充组合框
- 在文本编辑器中显示值,点击组合框:Yii 1.1.