**控制器代码:**
$http({method: 'GET',
url: '/proj_prof_table',
params: {id: id}
}).success(function(response)
{
$scope.data = response;
$scope.emp_id = [];
$scope.emp_name = [];
$scope.billing_status = [];
$scope.mgr = [];
$scope.mgr_id = [];
$scope.stdt = [];
for(i in $scope.data)
{
$scope.emp_id.push($scope.data[i].Emp_ID);
$scope.emp_name.push($scope.data[i].Emp_Name);
$scope.billing_status.push($scope.data[i].Billing_Status);
$scope.mgr.push($scope.data[i].Manager);
$scope.mgr_id.push($scope.data[i].Mgr_ID);
$scope.stdt.push($scope.data[i].Start_Date);
}
});
// Get client timeline
// Prepare Data
$http({method: 'GET',
url: '/proj_prof_client_timeline',
params: {id: clid}
}).success(function(response)
{
$scope.data = response;
alert($scope.data);
$scope.project = [];
$scope.stdt = [];
$scope.endt = [];
$scope.x = [];
for(i in $scope.data)
{
$scope.x[i] = [];
$scope.x[i].push($scope.data[i].Proj_Name);
$scope.x[i].push($scope.data[i].Start_Date);
$scope.x[i].push($scope.data[i].End_Date);
}
alert($scope.x[0]);
});
drawChart($scope.x);
}
//time line chart
google.charts.load('current', {'packages':['timeline']});
google.charts.setOnLoadCallback(drawChart);
function drawChart(param) {
//Chart code
var container = document.getElementById('timeline');
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'string', id: 'Projects' });
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
dataTable.addRows(param);
chart.draw(dataTable);
}
上面的代码抛出"给予addRows的参数必须是数字或数组"
除了$ scope.x是一个2D数组
还有其他方法可以将$ scope.x定义为[[ele,ele,ele],[ele,ele,ele],[ele,ele,ele]]数组,将其作为参数传递添加()
答案 0 :(得分:0)
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.emplist = [
{empname:'samudrala',empsalary:'4.5 - pam',empid:'Emp - 450'},
{empname:'soujanya',empsalary:'4.5 - pam',empid:'Emp - 451'},
{empname:'jai',empsalary:'4.5 - pam',empid:'Emp - 455'},
{empname:'Raamu',empsalary:'4.5 - pam',empid:'Emp - 459'}
];
$scope.addItem = function(){
$scope.emplist.push({'empname':$scope.empname,'empsalary':$scope.empsalary,'empid':$scope.empid});
$scope.empname = '';
$scope.empsalary = '';
$scope.empid = '';
}
$scope.remItem = function(item){
$scope.emplist.splice(item,1);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="myCtrl">
<table style="width:100%;">
<tr height="25" style=" background: #99ff00;">
<th width="5%"></th>
<th width="40%">EMP Name</th>
<th width="30%">EMP Salary</th>
<th width="">EMP ID</th>
<th width=""></th>
</tr>
<tr height="25" ng-repeat="x in emplist">
<td style="text-align: center;">{{$index}}</td>
<td style="text-align: center; ">{{x.empname}}</td>
<td style="text-align: center;">{{x.empsalary}}</td>
<td style="text-align: center;">{{x.empid}}</td>
<td style="text-align: center;"><button ng-click="remItem($index);" style="background:#00ffff; border:0px;">× Remove</button></td>
</tr>
<tr height="25">
<td><button ng-click="addItem();" style="background: #00ffff; border:0px; width:100%; height:100%;">Add</button></td>
<td style="padding:2px;"><input type="text" ng-model="empname" style="width:100%;" ></td>
<td style="padding:2px;"><input type="text" ng-model="empsalary" style="width:100%;" ></td>
<td style="padding:2px;"><input type="text" ng-model="empid" style="width:100%;" ></td>
</tr>
</table>
</div>