所以我有一系列活动,每个活动都有团队参与。这两个对象是相关的,但都不是另一个的属性。
我想要做的是循环每个事件并显示参与其中的每个团队。我尝试使用嵌套的ng-repeats来做到这一点。我的问题是内部ng-repeats仅在外部ng-repeat完成执行后才会显示。这意味着团队参与最后一次处理的事件将显示在每个表格中。
在我的控制器中,我有一组团队,每当我收到一个新事件时,我都会更新该数组,并且每个都有一个数组
这是我的重复表
<div ng-repeat="event in events" ng-init="getTeams(event.eventId)">
<div class="active title">Teams in {{event.eventName}} #{{event.eventId}}</div>
<table>
<thead>
<tr>
<th>Name</th>
<th>Sport</th>
<th>Motto</th>
<th>W-L-D</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="team in teams">
<td>{{team.teamName}}</td>
<td>{{team.teamSport}}</td>
<td>{{team.teamMotto}}</td>
<td>{{team.win}}- {{team.lose}} - {{team.draw}}</td>
<td>{{team.teamDescription}}</td>
</tr>
</tbody>
</table>
</div>
这是我的控制器
(function(){
angular
.module('foo')
.controller('EventController', function ($scope, $location, EventService) {
$scope.events = [];
$scope.targetEvent = {};
$scope.teams = [];
EventService.getEvents()
.then(function(events){
$scope.events = events;
});
$scope.getTeams = function(currEventId){
EventService.getTeams(currEventId)
.then(function(eventTeams) {
$scope.teams = eventTeams;
})
}
})()
我尝试使用track by但是通过eventId或teamId跟踪它似乎不起作用。提前感谢您的帮助
答案 0 :(得分:0)
虽然您每次都创建public class AlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context
.NOTIFICATION_SERVICE);
Intent repeatingIntent = new Intent(context,RepeatingActivity.class);
repeatingIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(context,100,repeatingIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
String contentTitle = intent.getStringExtra("contentTitle");
String contentText = intent.getStringExtra("contentText");
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.icon_notification)
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_notification))
.setContentTitle(contentTitle)
.setContentText(contentText)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setVibrate(new long[]{800,500,600,300})
.setLights(Color.GREEN, 500, 500)
.setAutoCancel(true);
notificationManager.notify(100,builder.build());
// Light up the screen
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
isScreenOn = pm.isInteractive();
}
else if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH){
isScreenOn = pm.isScreenOn();
}
if(isScreenOn==false)
{
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"MyLock");
wl.acquire(10000);
PowerManager.WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyCpuLock");
wl_cpu.acquire(10000);
}
}
}
变量。根据您当前的实施,它将是全球性的并且对于所有事件都是单一的。我不这么认为你应该在这里使用teams
,而是通过循环事件在控制器本身内执行该操作。
ng-init
然后,您只需将内部EventService.getEvents().then(function(events){
$scope.events = events;
//loop over each event.
events.forEach(function(event){
EventService.getTeams(currEventId)
.then(function(eventTeams) {
//placed specific teams on event level
event.teams = eventTeams;
})
})
});
更改为下方,然后移除ng-repeat
ng-init