沙箱编辑器并有一些我要插入此iframe的常量。我的常量列表如下:
<ul id="email-template-tag" style="margin:0px 0px 5px 0px;padding:0px;">
<?php foreach($tags as $key=>$value){?>
<li class="sms-template-tag sms-template-tag" data-value="<?php echo $key;?>"><?php echo $value;?></li>
<?php }?>
</ul>
下面给出了Javascript代码:
$(document).on('click','#email-template-tag li', function() {
var caretPos = document.getElementsByTagName('iframe')[0].contentWindow.getSelection();
var textAreaTxt = $('iframe.wysihtml5-sandbox').contents().find('html body').html();
var txtToAdd = $(this).attr('data-value');
$('iframe.wysihtml5-sandbox').contents().find('html body').html(textAreaTxt.substring(0, caretPos) + txtToAdd + textAreaTxt.substring(caretPos) ).focus();
});
但代码运行不正常。它总是在第一个位置插入li数据值。
答案 0 :(得分:1)
您可以使用insertHTML
editorInstance.composer.commands.exec(&#34; insertHTML&#34;,&#34; HTMLToInsert&#34;);
希望它有所帮助。
答案 1 :(得分:0)
$authors = App\Book::find(1)->authors;
$authorsNames = $authors->reduce(function ($carry, $author) {
$carry[] = $author->name;
return $carry;
}, array());