繁体   English   中英

如何限制用户在ui-ace编辑器中只编写一个javascript函数(方法)

[英]how to restrict user to write only one javascript function(method) inside of ui-ace editor

这是我的控制器代码

  $scope.aceOptions = {
      workerPath: 'http://localhost:50871/Scripts/app/vendor/',     
      useWrapMode: true,
      showGutter: true,
      theme: 'chrome',
      firstLineNumber: 1,
      onLoad: function (_editor) {
          $scope.script = {};
          $scope.script.scriptCode = "function fieldName_columnName_" + "functionName(){\n\n\n}";             
          var _session = _editor.getSession();
          _session.setMode('ace/mode/javascript');
          var _renderer = _editor.renderer;

          _session.on('changeAnnotation', function () {
              $scope.annotations = [];
              $scope.annotations = _editor.getSession().getAnnotations();
          }),
          _editor.$blockScrolling = Infinity;

          _session.on("change", function (e) {               
              var currentValue = _editor.getSession().getValue();
              $scope.script.scriptCode = currentValue;
          });


      },
      require: ['ace/ext/language_tools'],
      advanced: {
          enableSnippets: true,
          enableBasicAutocompletion: true,
          enableLiveAutocompletion: true
      }
  }

我为ui-ace写了指令这是我的html代码

 <javascript-editor code="script.scriptCode" ace-option="aceOptions"></javascript-editor>

和指令代码是

SCSApp
.directive('javascriptEditor', [
    function () {          
        return {
            restrict: 'E',
            scope: {
                data: '=code',
                aceOption: '='
            },
            templateUrl: '/Scripts/app/shared/directives/javascripEditor/partials/javascriptEditor.html',
            link: function (scope, element, attrs) {
            }
        }
    }]);

这是我的javascriptEditor.html

<div class="e1" ui-ace="aceOption" ng-model="data"></div>

我只想限制用户不要在ui-ace编辑器中编写更多的javascript函数

您可以创建自己的javascript简单函数解析器或使用类似parser3的lib

然后编写逻辑规则,根据ACE编辑器的内容显示UI的成功/失败。

它是像编译器一样解析的字符串/句子,以便创建低级代码。

您必须附加js函数,该函数将在文本编辑器中的keyDown或onBlur事件上触发。 该函数应该通过RegExp在编辑器中检查函数声明语句。 如果您找到多个函数声明匹配项,则可以在文本编辑器中声明多个函数时处理大小写。

暂无
暂无

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

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