我正在尝试选择数据并将其绑定到特定项目,但是一旦我选择了数据,我的所有项目现在都绑定到所选数据。如何为每个项目选择特定数据。
答案 0 :(得分:2)
您需要一个映射数据结构来保存每天的选择。可以有更好的方法,但很简单就可以像这样
$scope.data = {
"Monday": {workout: ''},
"Tuesday": {workout: ''},
"Wednesday": {workout: ''},
"Thursday": {workout: ''},
"Friday": {workout: ''},
"Saturday": {workout: ''},
"Sunday": {workout: ''}
}
并且您还需要跟踪所选的当前日期,以便您可以将所选的锻炼映射到该currentDay
键。
首先,当你打开锻炼选择器时设置curretDay
<a class="item" ng-repeat="day in days" ng-click="openModal(day.day)">{{data[day.day].workout}}
<span class="item-note">{{day.day}}</span>
</a>
和
$scope.openModal = function(day) {
$scope.currentDay = day;
$scope.modal.show();
};
其次,选择锻炼后,您需要在currentDay
键
<ion-radio class="item" ng-repeat="item in workouts" ng-value="item.workout" ng-model="data[currentDay].workout">{{item.workout}}</ion-radio>
以下是complete working demo(基于您的演示当然)