如何动态分配lite.userName变量。当用户登录到应用程序时,我需要将用户会话变量分配给lite.username,以便在CKEDITOR中跟踪更改将显示相应的用户。
默认情况下,我可以设置lite.userName ='Author';在config.js文件中。但是我找不到用会话分配该用户名的方法。
以下是我的CKEDITOR config.js文件。我正在使用MVC5和VS 2013
CKEDITOR.editorConfig = function( config ) {
config.extraPlugins = 'button,floatpanel,panel,panelbutton,quicktable,eqneditor';
config.skin = 'office2013';
config.width = 950;
config.height = 647;
// Remove unwanted buttons
config.removeButtons = 'Source,Save,NewPage,Preview,Templates,' +
'Simple Image Browser,ImageButton,Print,CreateDiv,' +
'Textarea,' +
'Form,Checkbox,Radio,TextField,Textarea,Select,Button,HiddenField,'+
//'BidiLtr,BidiRtl,Language,' +
'Format,Anchor,' +
'Flash,HorizontalRule,Smiley,PageBreak,Iframe,' +
'Font,FontSize,' +
'About';
config.floatingtools = 'Basic';
config.floatingtools_Basic =
[
['Bold', 'Italic', '-', 'NumberedList', 'BulletedList', '-', 'Link']
];
var lite = config.lite = config.lite || {};
lite.isTracking = false;
lite.userName = 'Author';
lite.userId = 'A';
lite.userStyles = {
"21": 3,
"15": 1,
"18": 2
};
lite.tooltipTemplate = "%a by %u";
};
Body.cshtml
@model System.Data.DataSet
@{
ViewBag.Title = "Body";
Layout = "~/Views/Shared/_ArticleLayout.cshtml";
}
@section scripts
{
@Scripts.Render("~/Scripts/ckeditor/ckeditor.js")
}
<div class="col-lg-12">
<div class="col-lg-12">
<div class="table-responsive">
<table id="table1" class="table table-bordered table-hover table-striped">
<tr>
<th>@Html.DisplayName("Body")
<fieldset>
<input id="ViewID" type="hidden" value="Body" name="ViewName">
</fieldset>
</th>
</tr>
<tr>
<td>
<textarea id="qMaxEditorSource" class="ckeditor">
@Html.Raw(HttpUtility.HtmlDecode(Model.Tables["General"].Rows[0][0].ToString()))
</textarea>
</td>
</tr>
</table>
</div>
</div>
</div>
最佳答案
我不知道任何那个MS代码,但是在纯JavaScript中,我会像这样执行“ configLoaded”事件。我还设置了我想使用的工具栏(我的配置文件中有几个)和语言环境。
var ckEditor = CKEDITOR.replace(node, { language: locale, toolbar: 'Extended'});
ckEditor.on('configLoaded', extendConfig);
function extendConfig() {
ckEditor.config.lite.userName = appConfig.getUserName();
ckEditor.config.lite.userId = appConfig.getUserId();
ckEditor.config.lite.isTracking = false;
}
appConfig是我的应用程序的模块。您可以替代任何东西。
有关配置的更多信息,请参见http://docs.ckeditor.com/#!/guide/dev_configuration