我有一个$(window).load(function(){});
来从服务器端获取所有数据并在页面中显示它们:
$(window).load(function(){
angular.element(document).scope().actualizarDias();
});
请注意,它有$scope.$on('$viewContentLoaded', function ($evt) {
$scope.actualizarDias();
});//not working
,它计算一行中的所有数据并呈现结果。数字变化时效果很好。
但是,我想在第一次加载页面时获得结果。现在结果字段为空,但如果我们按F5或更改一个数字,则所有结果都会正确显示。
正如我所看到的,如果我想使用jQuery函数,它们必须用Angular控制器定义,所以我试过:
从Angular控制器中定义setTimeout(function(){
$scope.$apply(function() {
$(window).load(function(){
$scope.actualizarDias();
});
});
});//not working
,如下所示:
jsp
在Angular控制器中定义以下函数:
<%
response.setHeader("Cache-Control","no-cache");
response.setHeader("Pragma","no-cache");
response.setDateHeader ("Expires", -1);
%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript">
angular.module('myApp').controller('myCtrl', function($scope, $modal, $window, $http, ProccessFormService) {
$scope.function1 = function() {...};
$scope.function2 = function() {....};
$scope.actualizarDias() = function() {...};
}
在Augular控制器中定义以下函数:
$scope.actualizarDias = function(){
tabla = document.getElementById('tablaProducciones').children[1];
$scope.impL="";
$scope.minutosTotalesL="";
$scope.minutosTotalesLFormat="";
for (var i=1; i<tabla.children.length*2; i++){
if (i%2!=0) {
var inputL = tabla.childNodes[i].cells[2].children[0].value;
var inputAct = tabla.childNodes[i].cells[0].innerHTML;
if($scope.impL=="" || $scope.impL==undefined){
$scope.impL=inputAct + "-" + inputL;
} else {
$scope.impL+=";" + inputAct + "-" + inputL;
}
if (!isNaN(inputL) && inputL>0){
if ($scope.minutosTotalesL=='' || $scope.minutosTotalesL==undefined){
$scope.minutosTotalesL=inputL;
} else {
$scope.minutosTotalesL=parseInt($scope.minutosTotalesL) + parseInt(inputL);
}
$scope.minutosTotalesLFormat = $scope.minutosAHoras($scope.minutosTotalesL);
}
}
}
}
无济于事。
我的脚本位于一个隔离的library(reshape2)
dcast(df,id+cat~item,value.var = "item",fun.aggregate =length)
文件中,结构如下:
import os
import sys
module_path = os.path.abspath(os.path.join('..'))
if module_path not in sys.path:
sys.path.append(module_path)
现在,当我第一次进入页面时如何加载结果?
我的计算功能是:
from project1.lib.module import function
# use the function normally
function(...)
答案 0 :(得分:0)
您可以在控制器主体中调用该函数,以确保在创建控制器时执行该函数:
function MyController() {
$scope.actualizarDias = function(){
...
}
$scope.actualizarDias();
}
虽然现在可能仍会失败,因为你的控制器中有很多特定于视图的视图,这是一个非常糟糕的主意。您应该更改代码的结构,以便将表中的数据加载到控制器中并绑定到该控制器而不是让控制器迭代表。