我动态生成一个div。我正在使用 引导程序面板 来显示div。 div的类可以是两个中的一个:面板面板成功或面板面板危险,这是根据我从服务器获得的响应数据决定的。服务器响应为成功或失败。
我想将上课成功或失败分配到上面的div和我的css文件中,我想说上课成功相当于面板面板成功,类失败相当于面板面板 - 危险
我使用的是ui-grid,而我所说的div是网格的一个单元格。它在statusTemplate1,statusTemplate2和statusTemplate3中定义。 以下是代码:
Javacsript文件
angular.module('Spectacle', ['ui.grid'])
.controller('SpectacleCtrl',
function($scope, $http, $q) {
$scope.loaded = true;
$scope.myData = [];
var statusTemplate1 = '<div class="panel panel-success">{{row.entity.build1.number}} <span class="label label-success">P-{{row.entity.build1.passCount}}</span> <span class="label label-danger">F-{{row.entity.build1.failCount}}</span> <span class="label label-warning">S-{{row.entity.build1.skipCount}}</span></div>';
var statusTemplate2 = '<div class="panel panel-success">{{row.entity.build2.number}} <span class="label label-success">P-{{row.entity.build2.passCount}}</span> <span class="label label-danger">F-{{row.entity.build2.failCount}}</span> <span class="label label-warning">S-{{row.entity.build2.skipCount}}</span></div>';
var statusTemplate3 = '<div class="panel panel-success">{{row.entity.build3.number}} <span class="label label-success">P-{{row.entity.build3.passCount}}</span> <span class="label label-danger">F-{{row.entity.build3.failCount}}</span> <span class="label label-warning">S-{{row.entity.build3.skipCount}}</span></div>';
$scope.gridOptions = { data: 'myData',rowHeight:62 };
$scope.gridOptions.columnDefs = [
{ field: 'job' },
{ field: 'build1',cellTemplate: statusTemplate1},
{ field: 'build2',cellTemplate: statusTemplate2},
{ field: 'build3',cellTemplate: statusTemplate3},
{ field: 'build4'},
{ field: 'build5'}
];
function fnGetList(url)
{
var deferred = $q.defer();
$http.get(url)
.success(function (data)
{
console.log("Data: " + data.buildList[0].number);
deferred.resolve(data);
});
return deferred.promise;
};
$scope.GetGridData = function ()
{
console.log("In GetGridData: " + "Getting the data");
$http.get('http://localhost:8989/api/job').
then(function(response) {
$scope.totalJobs = 2;
$scope.totalBuilds = 5;
console.log($scope.totalJobs);
$scope.jobs = response.data.jobs;
$scope.loaded = false;
console.log($scope.jobs);
console.log('size of the response data:'+ response.data.jobs.length +' ');
for(var i=0; i<response.data.jobs.length; i++)
{
console.log('The jobid for job '+i+' is:'+response.data.jobs[i].id);
var url = "http://localhost:8989/api/job/"+response.data.jobs[i].id+"";
fnGetList(url).then(function (content)
{
// Assuming your content.data contains a well-formed JSON
console.log('Content: '+content.name);
if (content !== undefined)
{
console.log('promise success: '+content);
console.log('printing grid options:'+$scope.gridOptions.data);
$scope.myData.push({
"job": content.name,
"build1": content.buildList[0],
"build2": content.buildList[1],
"build3": content.buildList[2]
// "build4": content.buildList[3].number,
// "build5": content.buildList[4].number
});
}
});
}
});
};
});
HTML代码
<div class="gridStyle" ui-grid="gridOptions" ng-init="GetGridData()"></div>
答案 0 :(得分:0)
这就是我修复它的方法:
'<div ng-class="\'{{row.entity.build2.status}}\'? \'panel panel-success\' : \'panel panel-danger\'">{{row.entity.build2.number}} <span class="label label-success">P-{{row.entity.build2.passCount}}</span> <span class="label label-danger">F-{{row.entity.build2.failCount}}</span> <span class="label label-warning">S-{{row.entity.build2.skipCount}}</span></div>';
对 ng-class
使用条件语句( condition?true:false )