【发布时间】:2014-11-18 14:33:58
【问题描述】:
我正在尝试引用数组中的一项,但我不知道为什么这不起作用,
console.log($scope.Times);
console.log($scope.Times[0]);
这两行代码彼此完全一致,但我从控制台得到的输出如下..
任何想法为什么这不起作用?正如我之前提到的,这些命令彼此完全一致,并且在同一个函数中,变量在我的控制器中是全局的。
如果您认为有帮助,我可以添加更多代码,但我真的不明白如何..
更多代码:
$scope.Times = [];
$scope.getStatus = function(timer){
$http.post('getStatus.php', {timer : timer})
.success(function(response){
$scope.response = response;
if ($scope.response.Running === "0"){
$scope.model = { ItemNumber : $scope.response.Part };
$scope.loadTiming($scope.response.Part);
console.log($scope.Times);
console.log($scope.Times[0]);
}
});
};
$scope.loadTiming = function(itemNumber) {
$http.post('getPartTimings.php', {itemNumber : itemNumber})
.success(function(response){
$scope.selectedTiming = response;
$scope.Times.splice(0);
var i = 0;
angular.forEach($scope.selectedTiming, function(value) {
if (value !== 0)
$scope.Times.push({
"Process" : $scope.procedures[i],
"Duration" : value*60
});
i++;
});
});
};
<?php
$postData = file_get_contents("php://input");
$request = json_decode($postData);
require "conf/config.php";
mysqli_report(MYSQLI_REPORT_STRICT);
try {
$con=mysqli_connect(DBSERVER,DBUSER,DBPASS,DBNAME);
} catch (Exception $exp) {
echo "<label style='font-weight:bold; color:red'>MySQL Server Connection Failed. </label>";
exit;
}
$query = 'SELECT *,
TIME_TO_SEC(TIMEDIFF(NOW(),Timestamp))
FROM live_Timers
WHERE Timer='.$request->timer;
$result = mysqli_query($con, $query);
$data = mysqli_fetch_assoc($result);
echo JSON_ENCODE($data);
感谢您的帮助。
【问题讨论】:
-
更多代码可能会有所帮助,因为根据您现在的情况,我认为没有问题。
-
更多代码将有助于识别整个上下文以及可能影响数组的其他内容。
-
它可以在 Firefox 中使用吗?可能与this bug有关。
标签: javascript arrays angularjs