Angularjs performance

北慕城南 提交于 2019-12-12 02:58:46

问题


I have a project that needs a good performance with a large number of records showed.

My data structure:

  • SERVERS (+- 15 per page)
    • WEBSITES (+- 20 per server)
      • USERS logged in with your STATUS (+- 500 per website)

What is the best approach for my Objects and Controllers?

  1. One Controller with one neasted object.

    ServerCtrl -> $scope.Server[0].Websites[0].Users

  2. One Controller with three lists

    ServerCtrl -> $scope.Servers; $scope.Websites; $scope.Users

  3. Three Controllers with three separated lists

    ServerCtrl -> $scope.Servers

    WebsiteCtrl -> $scope.Websites

    UserCtrl -> $scope.Users

Thanks!


回答1:


It all depends on how you are working with the data in the controller.

  1. If you need access to all data for a specific server. Then you need data to the data inside the data. But it is a lot of data so maybe just read one server at the time or page?
  2. I would instead only read one service at the time. But it all depends on what you want to do. Are the server, website and user not connected to each other then fine.
  3. This approach works. Inside the server view you can have a website view with a controller and inside the website view you can have a user controller. It is a good way organize data. But the amount of data means that you probably need some sort of paging.



回答2:


The performance depends on how you manipulate the data. So you can use AngularJS Batarang (Chrome Extension) and check the number os watcher in your page and apply some methods to reduce this number and give more performance for your application. Be careful with big lists and two way data binding, filters... They're villains of performance.



来源:https://stackoverflow.com/questions/16763463/angularjs-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!