这是我实施的解决方案
文本区
<textarea id="custInfoPriorPerformance" rows="10" cols="20" data-bind="kendoEditor: { value: AccountPlanVM.AccountPlan.PriorYearSummary }" > </textarea>
在 View Model 中使用控件的 Id、observable 和占位符文本创建一个 options 变量
self.PlaceholderOptions =
{
CustomerInfoAccountBackground: ['#custInfoAccountBackground', self.AccountPlanVM.AccountPlan.AccountBackground, "<div style=\"" + self.PlaceholderStyle + "\">" + 'Placeholder Example Text' + "</div>"]
};
加载时,我绑定到编辑器框的焦点/模糊。在发回表单之前,我从 observables 中清除了占位符文本。
//Editor Placeholder methods
self.BindEditorPlaceholders = function() {
for (var propt in self.PlaceholderOptions) {
//Options array
var options = self.PlaceholderOptions[propt];
// get a reference to the Editor
var editor = $(options[0]).data("kendoEditor");
//Currently saved value
var currentValue = options[1]();
//If we don't have any text saved, inject placeholder
if (!currentValue) {
editor.value(options[2]);
}
//Attach Events to Editor Iframe
$(options[0]).siblings(".k-content").focus(options, self.EditorFocus);
$(options[0]).siblings(".k-content").blur(options, self.EditorBlur);
}
};
self.EditorFocus = function(e) {
//Options array
var options = e.data;
// get a reference to the Editor
var editor = $(options[0]).data("kendoEditor");
//Current editor value
var htmlValue = editor.value();
if (htmlValue == options[2]) {
//Clear editor value
editor.value('');
}
};
self.EditorBlur = function (e) {
//Options array
var options = e.data;
// get a reference to the Editor
var editor = $(options[0]).data("kendoEditor");
//Current editor value
var htmlValue = editor.value();
if (htmlValue == '') {
//Set editor value back to placeholder
editor.value(options[2]);
}
};
self.CleanEditorPlaceholders = function() {
for (var propt in self.PlaceholderOptions) {
//Options array
var options = self.PlaceholderOptions[propt];
// get a reference to the Editor
var editor = $(options[0]).data("kendoEditor");
//Currently saved value
var currentValue = options[1]();
//If the current text is the placeholder, wipe it out
if (currentValue == options[2]) {
options[1]('');
}
}
};