我怎样才能完成这个AngularJS任务?
我把我正在使用的代码放在Plunker中 这两个阵列平行于:我怎样才能完成这个AngularJS任务?,angularjs,Angularjs,我把我正在使用的代码放在Plunker中 这两个阵列平行于: var buildingFloors=['GR','01','02']; 显示将使用哪些楼层 此阵列包含所有可能的楼层: var floors =[{ name:"Ground Floor", initial:"GR", },{ name:"1st Floor", initial:"01", },{ name:"2nd Floor", initial:"02", },{ nam
var buildingFloors=['GR','01','02'];
显示将使用哪些楼层
此阵列包含所有可能的楼层:
var floors =[{
name:"Ground Floor",
initial:"GR",
},{
name:"1st Floor",
initial:"01",
},{
name:"2nd Floor",
initial:"02",
},{
name:"3rd Floor",
initial:"03",
}];
for循环搜索buildingFloors
和floors
以创建两个对象:
for(i=0;i<buildingFloors.length;i++){
for(c=0;c<floors.length;c++){
if(floors[c].initial == buildingFloors[i]){
$scope.arFiles.push({
floor:floors[i].name, initial:floors[i].initial, status:arFloorStatus[c]
});
$scope.spFiles.push({
floor:floors[i].name, initial:floors[i].initial, status:spFloorStatus[c]
});
}
}
}
我的第一个想法是克隆对象,而不是包含spFiles
的ng repeat,它可以包含一个通用名称,即设置要使用的对象的克隆,但是克隆对象对于我的任务来说似乎过于复杂。我希望有一种更“有棱角的方式”来完成我的任务,但我不知道如何去做
大致如下:
$scope.switchObj = function(newObj){
if(newObj == "ar"){
//somehow switch the object being used in the ng-repeat.
}
}
你说的“克隆”是什么意思
这应该起作用:
<tr ng-repeat = "x in files">
<th scope="row">{{x.floor}}</th>
<td>AR{{x.initial}}.pdf {{x.status}} {{x.labelname}}</td>
<td>AR{{x.initial}}.dwf {{x.status}} {{x.labelname2}}</td>
<td>AR{{x.initial}}.dwg {{x.status}} {{x.labelname3}}</td>
</tr>
请参阅以下工作说明:
$scope.switchObj = function(newObj){
if(newObj == "ar"){
//somehow switch the object being used in the ng-repeat.
}
}
<tr ng-repeat = "x in files">
<th scope="row">{{x.floor}}</th>
<td>AR{{x.initial}}.pdf {{x.status}} {{x.labelname}}</td>
<td>AR{{x.initial}}.dwf {{x.status}} {{x.labelname2}}</td>
<td>AR{{x.initial}}.dwg {{x.status}} {{x.labelname3}}</td>
</tr>
$scope.switchObj = function(newObj){
if(newObj == "ar"){
$scope.files = newObj;
}
}