简体   繁体   English

如何使用CDN中的requirejs加载ace编辑器?

[英]How to load ace editor with requirejs from CDN?

I am trying to load the ace editor from a CDN with requirejs. 我正在尝试使用requirejs从CDN加载ace编辑器。

Here is a plunkr which illustrates my problem. 是一个说明我问题的小插曲。 Ace is not defined in the following case: 在以下情况下不定义Ace:

requirejs.config({
  paths: { ace: ['//cdnjs.cloudflare.com/ajax/libs/ace/1.1.9/ace'] }
})

$('h1').text("loading ace...");
requirejs([ 'ace'], function(ace) {
  $('h1').text("ace loaded.")
  console.log(ace)
  ace.edit('#editor')
  return
})

you need to define ace as a path to the folder that contains ace.js and require "ace/ace" 您需要将ace定义为包含ace.js的文件夹的路径,并需要“ ace / ace”

 requirejs.config({ paths: { ace: ['//cdnjs.cloudflare.com/ajax/libs/ace/1.1.9/'] } }) $('h1').text("loading ace..."); requirejs(['ace/ace'], function(ace) { $('h1').text("ace loaded.") console.log(ace) ace.edit('editor') }) 
 <!DOCTYPE html> <html> <head> <script src="http://requirejs.org/docs/release/2.1.14/minified/require.js"></script> <script src="http://code.jquery.com/jquery-2.1.4.min.js"></script> </head> <body> <h1>Hello Plunker!</h1> <div id='editor' style="height:200px"></div> </body> </html> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM