如何使用CDN中的requirejs加载ace编辑器? [英] How to load ace editor with requirejs from CDN?

查看:129
本文介绍了如何使用CDN中的requirejs加载ace编辑器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用requirejs从CDN加载ace编辑器。

I am trying to load the ace editor from a CDN with requirejs.

这里是个笨拙的例子,它说明了我的问题。在以下情况下未定义Ace:

Here is a plunkr which illustrates my problem. Ace is not defined in the following case:

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
})


推荐答案

您需要将ace定义为包含 ace.js
且需要 ace / ace

you need to define ace as a path to the folder that contains ace.js and require "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>

这篇关于如何使用CDN中的requirejs加载ace编辑器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆