Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/405.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何限制用户在ui ace编辑器中只编写一个javascript函数(方法)_Javascript_Angularjs_Angularjs Directive_Angularjs Scope_Angularjs Ng Repeat - Fatal编程技术网

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

如何限制用户在ui ace编辑器中只编写一个javascript函数(方法),javascript,angularjs,angularjs-directive,angularjs-scope,angularjs-ng-repeat,Javascript,Angularjs,Angularjs Directive,Angularjs Scope,Angularjs Ng Repeat,这是我的控制器代码 $scope.aceOptions = { workerPath: 'http://localhost:50871/Scripts/app/vendor/', useWrapMode: true, showGutter: true, theme: 'chrome', firstLineNumber: 1, onLoad: function (_editor) { $sco

这是我的控制器代码

  $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>
这是我的javascriptEditor.html

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


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

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

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


它是字符串/句子解析,就像编译器为了创建低级代码所做的那样。

您必须附加js函数,该函数将在文本编辑器中的keyDown或onBlur事件中触发。 该函数应该在编辑器中检查函数声明语句的文本。
如果你能找到一个以上的函数声明匹配项,你就可以在文本编辑器中处理多个函数声明的情况。

我能请你在plunker中执行吗?我没有找到你,我是ace新手editor@SyedRasheed这是一个获取ace编辑器代码值并运行一些逻辑(您自己的简单解析器)的示例正如我在回答中所说的,您可以使用一个更复杂的库,它是为javascript代码解析而设计的。
<div class="e1" ui-ace="aceOption" ng-model="data"></div>