异步处理DOM以提高性能

时间:2015-05-08 17:24:13

标签: jquery angularjs html5

我正在使用html5,angularjs,jquery和websocket进行Web项目。我目前只在Google Chrome上进行测试。

这从一些基础数据开始,但数据通过WebSockets更改。当许多数据出现时,问题就出现了。该网站经历长时间的延迟和崩溃,因为网站在很短的时间内收到大量数据,然后我需要时间来处理每个数据。如果有任何方法可以异步操作DOM,那么每个数据都将在不同的线程上处理,因此滞后将不存在。

下面我列出几行来看看我尝试过的内容:

websocket(是参考)

ws = new window[support]('ws://xx.xxx.xxx.xx:port/');

                    // when data is comming from the server, this method is called
ws.onmessage = function (evt) {
    // Here I proccess the message
    // I walk the whole message, looking at the object id
    for(.....){
       if(...){//i find the id, them i change the data
          //each materials for stundet finded
           for($x=0;$x<=evt.data[0].student[0].materials.length.....
                    $scope.data[0].students[$idfind].materials[$x]=evt.data[0].student[0].materials[$x]
          }
        }

    }
    .....
    ....
}

接下来,我用这样的角度显示数据:

<div ng-repeat="student in data[0].students">
   Name :{{studen.Name}}
   ....
   ....
   ....
   <div ng-repeat="material in student.materials">
     Material :{{material.name}}
     Calification :{{material.calification}}
    ...
    ....
   ....
   </div>

</div

这只是一个例子,因为每个学生都有大约25-30个项目,每条信息都会出现(0.3 - 1.2秒)。

0 个答案:

没有答案