【发布时间】:2017-08-14 05:17:51
【问题描述】:
我正在使用 Angular 和 Rails 应用程序
我有一个演示应用程序。我需要显示加载角度响应所需的响应时间
举个例子。
我正在加载包含 100 k 个元素的数组的响应。我想显示百分比从 0% 开始并作为响应负载递增。加载完整响应后,它会完成 100% 的响应时间
文件使用说明
/app/views/layouts/application.html.erb
<!DOCTYPE html>
<html>
<head>
<title>Anguler</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
/app/views/pages/index.html.erb
<div ng-app="myApp" ng-controller="customersCtrl">
<ul>
<li ng-repeat="x in myData">
{{ x }}
</li>
</ul>
</div>
/app/controllers/pages_controller.rb
class PagesController < ApplicationController
def index
@arr = []
for n in 1..100000
@arr.push(n)
end
return render json: @arr
end
end
/app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
end
/assets/javascripts/application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require angular.min
//= require custom.min
/assets/javascripts/custom.js
var app = angular.module('myApp');
app.controller('customersCtrl', function($scope, $http) {
$http.get("/").then(function (response) {
$scope.myData = response.data.records;
}
});
让我知道如何以百分比显示加载时间百分比
提前致谢
【问题讨论】:
-
为什么要在页面上呈现
100k元素,在这种情况下浏览器会死掉,因为ng-repeat有效,使用分页或在向下滚动时延迟加载记录会有效 -
这不是我将设法减少数据的问题。我在演示应用程序中使用了 100000,因为在我的实时应用程序中,我必须使用这个百分比响应,并且没有大量记录。
标签: javascript ruby-on-rails angularjs ruby