我需要一些帮助将模型正确绑定到复选框列表(Mon-Sun)。
感谢任何帮助。感谢。
服务器型号
public class DailySchedule : ReportSchedule
{
public string Option { get; set; }
public Dictionary<string, bool> RunOnDays { get; set; }
}
我从服务器收到的JSON数据采用以下格式:
vm.reportSchedule
{
"Option": "EveryWeekday",
"RunOnDays": {
"Mon": true,
"Tue": true,
"Wed": true,
"Thu": true,
"Fri": true,
"Sat": false,
"Sun": false
}
}
HTML
<div class="form-group">
<input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Mon">Mon
<input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Tue">Tue
<input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Wed">Wed
<input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Thu">Thu
<input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Fri">Fri
<input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Sat">Sat
<input type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays" value="Sun">Sun
</div>
答案 0 :(得分:2)
使用带键/ val语法的ngRepeat
:
<div class="form-group">
<input ng-repeat="(day, bool) in vm.reportSchedule.RunOnDays" type="checkbox" name="dailyOption" ng-model="vm.reportSchedule.RunOnDays[day]" />{{day}}
</div>