【发布时间】:2018-03-24 20:21:31
【问题描述】:
我正在运行 Umbraco 版本 7.9.2 并关注 this tutorial 以了解如何创建自定义属性编辑器。
我的第一步是创建一个名为 MarkDownEditor 的文件夹
我的第二步是创建一个名为 package.manifest.json 的文件
{
//you can define multiple editors
"propertyEditors": [
{
/*this must be a unique alias*/
"alias": "My.MarkdownEditor",
/*the name*/
"name": "My markdown editor",
/*the icon*/
"icon": "icon-code",
/*grouping for "Select editor" dialog*/
"group": "Rich Content",
/*the HTML file we will load for the editor*/
"editor": {
"view": "~/App_Plugins/MarkDownEditor/markdowneditor.html"
}
}
],
//array of files we want to inject into the application on app_start
"javascript": [
"~/App_Plugins/MarkDownEditor/markdowneditor.controller.js"
]
}
然后我在 MarkDownEditor 目录下创建了两个文件:markdowneditor.controller.js 和 markdowneditor.html
markdowneditor.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div ng-controller="My.MarkdownEditorController">
<textarea ng-model="model.value"></textarea>
</div>
</body>
</html>
markdowneditor.controller.js
angular.module("umbraco")
.controller("My.MarkdownEditorController",
//inject umbracos assetsService
function ($scope, assetsService) {
//tell the assetsService to load the markdown.editor libs from the markdown editors
//plugin folder
assetsService
.load([
"~/App_Plugins/MarkDownEditor/lib/Markdown.Converter.js",
"~/App_Plugins/MarkDownEditor/lib/Markdown.Sanitizer.js",
"~/App_Plugins/MarkDownEditor/lib/Markdown.Editor.js"
])
.then(function () {
//this function will execute when all dependencies have loaded
alert("editor dependencies loaded");
console.log('stuff has loaded!');
});
//load the separate css for the editor to avoid it blocking our js loading
assetsService.loadCss("~/App_Plugins/MarkDownEditor/lib/Markdown.Editor.css");
});
最后,我在Umbraco CMS中注册了编辑器,放到一个简单的文档类型中,最终在多个浏览器中访问了页面。
而且……我什么也没看到。似乎编辑器正在工作(我认为),但我不明白为什么我没有看到控制器中包含的警报或 console.log。我做错什么了?我已经尝试了多个浏览器,所以我知道这不是缓存问题,并且我确保在 Visual Studio 中重建项目。
编辑 1:
根据建议,我尝试修改 assetsService 文件路径,因为 ~ 似乎是 C# 的东西,而我的控制器是 javascript 文件。现在是这个样子
.load([
"/App_Plugins/MarkDownEditor/lib/Markdown.Converter.js",
"/App_Plugins/MarkDownEditor/lib/Markdown.Sanitizer.js",
"/App_Plugins/MarkDownEditor/lib/Markdown.Editor.js"
])
但是,我仍然没有看到警报或控制台日志。
我确实意识到我做错的一件事是没有在降价模板中包含我的降价值。我已经这样做了,现在可以看到我在创建新的降价页面时放入编辑器的内容。
【问题讨论】:
-
用于加载文件的
~/表示法可能不起作用,因为它是 C# 的东西。所以文件不会被加载并且承诺永远不会被履行,所以没有警报。将~/App_Plugins/MarkDownEditor替换为./,我想你会看到警报 -
我按照你的建议做了。没有。我注意到我没有在页面上看到我的内容。所以我确保将 My.MarkdownEditorController 添加到 makrdownTester 模板中。我现在可以看到我的内容,但我仍然看不到我的 console.log 或警报。
-
如果只替换
~,那么将~/App_Plugins/MarkDownEditor/lib/Markdown.Converter.js更改为/App_Plugins/MarkDownEditor/lib/Markdown.Converter.js。你能显示更新的代码吗? -
帖子已更新。
标签: javascript umbraco umbraco7