MVC5
使用此CKEditor 文档中的信息,我最终能够从 MVC 方法/视图集成图像选择过程,该方法/视图显示可用图像列表,可以使用 CKEditor 插入到文本区域中。
虽然最终的解决方案非常简单,但整个过程并不是特别直观。我最终会发布我的解决方案,因为我确信许多相对较新的 MVC 编码人员,例如我自己,正在为这个功能寻找简单直接的解决方案。但与此同时,
下面的代码显示了上面链接中示例 2中的相关行,稍微重新排列。
<body>
<button onclick="returnFileUrl()">Select File</button>
</body>
<script>
function getUrlParam( paramName ) { // Helper function to get parameters from the query string.
var reParam = new RegExp( '(?:[\?&]|&)' + paramName + '=([^&]+)', 'i' );
var match = window.location.search.match( reParam );
return ( match && match.length > 1 ) ? match[1] : null;
}
function returnFileUrl() { // Simulate user action of selecting a file to be returned to CKEditor
var funcNum = getUrlParam( 'CKEditorFuncNum' );
var fileUrl = '/path/to/file.txt';
window.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl );
window.close();
}
</script>
我从来不知道如何使用getUrlParam()。我最终绕过了它,并使用已传递给我的图像选择器方法的确切参数通过变量funcNum馈送。一旦我这样做了,CKEditor 的示例代码就工作得很好。
但是那个getUrlParam()函数在做什么呢?我只是名义上理解正则表达式,而这个完全让我无法理解。谁能解释为什么它甚至被建议?