如何使用 angularjs 将相同的数据绑定到不同的选项?

How do I bind the same data to different options using angulajs?

我正在尝试 select 数据并将其绑定到特定项目,但是一旦我 select 数据,我的所有项目现在都绑定到 selected数据。我怎样才能 select 我的每个项目的具体数据。

这是我的演示。 http://play.ionic.io/app/cb25b106e671

您需要一个映射数据结构来保存每天的选择。可以有更好的方法,但很简单,它可以像这样

  $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(当然基于您的演示)