5

我一直在使用 visjs.org/docs/timeline/ 来显示数据的时间线视图。我有一个指令,它从 API 获取数据并使用该$compile方法创建模板。

<vis-timeline timeline-data="apiData"></vis-timeline>

linkFn我迭代数据以创建模板的范围时,该范围将作为 vis 的内容传递DataSet

link: function(scope,element,attr){
   if(scope.roster.timelineData){

     angular.forEach(scope.roster.timelineData, function(){

     //Create a scope for the directive used for vis DataSet
     var templateScope = scope.$new(true);//create an isolated scope

     templateScope.name = 'templateData';
     //this can be different for each iteration

     var template = $compile('<timeline-item template-data="name"></timeline-item>')(templateScope)[0];

     });
   }
 }

我将编译后的模板作为 vis 的内容推DataSet送到时间轴中。尽管这种方法效果很好,但构建时间线大约需要 10 秒。对时间线的任何编辑都需要 10 秒才能反映。

如果我添加一个普通模板而不是它,它确实会快速添加。如何提高编译模板的速度?

4

0 回答 0