特定のフィールドで htmleditor を使用する必要がある場合。そのため、htmleditor を使用するフィールドごとに、jquery を使用して htmleditor をレンダリングするエディター テンプレートを作成し、そのために UIHint を使用します。
@model System.String
<script type="text/javascript" src="~/Scripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" language="javascript">
tinyMCE.init({
mode: "textareas",
theme: "advanced",
editor_selector: "htmlmarker",
theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter, justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace, |,bullist,numlist,|,outdent,indent, blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code, |,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3: "hr,removeformat,visualaid,|,sub,sup",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left"
});
</script>
@Html.TextAreaFor(model => model, new {@class="htmlmarker" })
今ではevreythingは正常に動作しますが、実行時にソースを表示すると、UIHintを使用するすべてのフィールドに対してjqueryスクリプトが参照され、複数回呼び出されることがわかります。JavaScriptコードの重複を防ぐメカニズムはありますか?