[英]Setting initial value for ng-model in ng-options
我已经在Stack Overflow上搜索了我的问题的答案,但似乎找不到有效的解决方案。
我有两个遵循此格式的选择标签:
select(required class='form-control nf-input' ng-model='Game.loadedGame.teams[0].teamInfo' ng-change='Game.addTeam(Game.loadedGame.teams[0])',
ng-options='team.name for team in Game.teams | orderBy:"name" | preventSameMatchTeams:Game.loadedGame.teams[1].teamInfo.id'
)
我试图通过在服务器以正确的数据响应后将Game.loadedGame传递给此函数来初始化此选择的ng模型:
function setLoadedGameTeams(loadedGame, teams) {
loadedGame.teams.forEach(matchTeam => {
let index = teams.findIndex(team => team.id === matchTeam.id);
if (index !== -1) {
matchTeam.teamInfo = teams[index];
}
});
}
在我为每个团队设置了teamInfo属性后,即使该视图已正确更新以显示每个团队的信息,选择下拉列表也不会更改为正确的选项。
任何帮助表示赞赏!
我发现的解决方案非常简单。 我只需要向ng-options添加曲目即可!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.