在angularJS中更新数组的数据

时间:2016-09-06 16:17:12

标签: javascript angularjs arrays json

我要做的是制作一个简单的应用程序,用户可以在工作日编辑其可用性。代码工作正常..我从选择框中获取数据,但问题是当我试图更新星期一的数据星期二数据时也使用相同的星期一**更新(正如你在上一个视图中看到的那样) )**

我的db JSON

"doctorSchedule" : [ 
        {
            "_id" : null,
            "working_day" : "Monday",
            "working_from" : [ 
                {
                    "_id" : null,
                    "hours" : "9",
                    "minutes" : "30"
                }
            ],
            "working_to" : [ 
                {
                    "_id" : null,
                    "hours" : "6",
                    "minutes" : "30"
                }
            ]
        }, 
        {
            "_id" : null,
            "working_day" : "Tue",
            "working_from" : [ 
                {
                    "_id" : null,
                    "hours" : "9",
                    "minutes" : "30"
                }
            ],
            "working_to" : [ 
                {
                    "_id" : null,
                    "hours" : "6",
                    "minutes" : "30"
                }
            ]
        }
    ],

我的角色代码。

$scope.data1 = $stateParams.viewUser;
$http({ 
    url: "/getinfo",
    method: "POST",
    headers :{'Content-Type': 'application/json','Accept': 'application/json'},
    data: dataParam    
}).success(function(response) { 
    if(response.status_code == "worked") {
      $scope.viewUser = response.clinicUserVo;
      $scope.datasc = response.doctorSchedule;                              
    } 
});

我的HTML文件

 <table class="table table-bordered" ng-repeat="docSchedule in data1.doctorSchedule">
<tr>  <th scope="col"><input type="checkbox"  ng-model="data1.working_day"></th>
                                            <td>{{docSchedule.working_day}}</td>
                                            <td>

            <select  id="user_time_zone"   class="form-control form-group" ng-model="data1.working_from">

                                    <option value="" >{{docSchedule.working_from[0].hours}}</option>
                                                    <option id="optionspec" value="01" >01</option>
                                                    <option id="optionspec" value="02" >02</option>
                                                    <option id="optionspec" value="03" >03</option>
                                                    <option id="optionspec" value="04" >04</option>
                                                    <option id="optionspec" value="05" >05</option>
                                                    <option id="optionspec" value="06" >06</option>
                                                    <option id="optionspec" value="07" >07</option>
                                                    <option id="optionspec" value="08" >08</option>
                                                    <option id="optionspec" value="09" >09</option>
                                                    <option id="optionspec" value="10" >10</option>
                                                    <option id="optionspec" value="11" >11</option>
                                                    <option id="optionspec" value="12" >12</option>
                                                    <option id="optionspec" value="13" >13</option>
                                                    <option id="optionspec" value="14" >14</option>
                                                    <option id="optionspec" value="15" >15</option>
                                                    <option id="optionspec" value="16" >16</option>
                                                    <option id="optionspec" value="17" >17</option>
                                                    <option id="optionspec" value="18" >18</option>
                                                    <option id="optionspec" value="19" >19</option>
                                                    <option id="optionspec" value="20" >20</option>
                                                    <option id="optionspec" value="21" >21</option>
                                                    <option id="optionspec" value="22" >22</option>
                                                    <option id="optionspec" value="23" >23</option>
  </select>

                                                <td>
                <div class="col-md-12 col-sm-6 col-xs-12 form-group has-feedback">
                <select  id="user_time_zone"  class="form-control form-group"  ng-model="data1.working_from"> 
                            <option value="" disabled="disabled">{{docSchedule.working_from[0].minutes}}</option>
                                                    <option id="optionspec" value="" >00</option>
                                                    <option id="optionspec" value="05" >05</option>
                                                    <option id="optionspec" value="10" >10</option>
                                                    <option id="optionspec" value="15" >15</option>
                                                    <option id="optionspec" value="20" >20</option>
                                                    <option id="optionspec" value="25" >25</option>
                                                    <option id="optionspec" value="30" >30</option>
                                                    <option id="optionspec" value="35" >35</option>
                                                    <option id="optionspec" value="40" >40</option>
                                                    <option id="optionspec" value="45" >45</option>
                                                    <option id="optionspec" value="50" >50</option>
                                                    <option id="optionspec" value="55" >55</option>
                                                    </select>
                                                </div>
                                            </td>
                                            </td>
                                            <td><b>to</b></td>
                                            <td>
                                                <div class="col-md-12 col-sm-6 col-xs-12 form-group has-feedback">
                                                     <select  id="user_time_zone"  class="form-control form-group"  ng-model="data1.working_to" name="user_time_zone">
                                                    <option value="" disabled="disabled">{{docSchedule.working_to[0].hours}}</option>
                                                    <option id="optionspec" value="" >00</option>
                                                    <option id="optionspec" value="05" >05</option>
                                                    <option id="optionspec" value="10" >10</option>
                                                    <option id="optionspec" value="15" >15</option>
                                                    <option id="optionspec" value="20" >20</option>
                                                    <option id="optionspec" value="25" >25</option>
                                                    <option id="optionspec" value="30" >30</option>
                                                    <option id="optionspec" value="35" >35</option>
                                                    <option id="optionspec" value="40" >40</option>
                                                    <option id="optionspec" value="45" >45</option>
                                                    <option id="optionspec" value="50" >50</option>
                                                    <option id="optionspec" value="55" >55</option>
                                                    </select>
                                                </div>
                                            </td>
                                            <td><b>:</b></td>
                                            <td>
                                                <div class="col-md-12 col-sm-6 col-xs-12 form-group has-feedback">
                                                <select  id="user_time_zone" class="form-control  form-group"  ng-model="data1.working_to"  name="user_time_zone">
                                                    <option value="" disabled="disabled">{{docSchedule.working_to[0].minutes}}</option>
                                                    <option id="optionspec" value="" >00</option>
                                                    <option id="optionspec" value="01" >01</option>
                                                    <option id="optionspec" value="02" >02</option>
                                                    <option id="optionspec" value="o3" >03</option>
                                                    <option id="optionspec" value="04" >04</option>
                                                    <option id="optionspec" value="05" >05</option>
                                                    <option id="optionspec" value="06" >06</option>
                                                    <option id="optionspec" value="07" >07</option>
                                                    <option id="optionspec" value="08" >08</option>
                                                    <option id="optionspec" value="09" >09</option>
                                                    <option id="optionspec" value="10" >10</option>
                                                    <option id="optionspec" value="11" >11</option>
                                                    <option id="optionspec" value="12" >12</option>
                                                    <option id="optionspec" value="13" >13</option>
                                                    <option id="optionspec" value="14" >14</option>
                                                    <option id="optionspec" value="15" >15</option>
                                                    <option id="optionspec" value="16" >16</option>
                                                    <option id="optionspec" value="17" >17</option>
                                                    <option id="optionspec" value="18" >18</option>
                                                    <option id="optionspec" value="19" >19</option>
                                                    <option id="optionspec" value="20" >20</option>
                                                    <option id="optionspec" value="21" >21</option>
                                                    <option id="optionspec" value="22" >22</option>
                                                    <option id="optionspec" value="23" >23</option>
                                                </select>

                                                </div>
                                            </td>

                                        </tr>






                                 <tr>

</tr>
<tr >


</table>

HTML视图

当我试图更新单日数据时,在这个html页面中看到tue数据也会自动改变我如何通过Angular解决它?

enter image description here

1 个答案:

答案 0 :(得分:0)

更改

Output=gaussianBlurSepTest(double(inputImage)); Output=uint8(Output);

<select id="user_time_zone" class="form-control form-group" ng-model="data1.working_from">

因此,<select id="user_time_zone" class="form-control form-group" ng-model="docSchedule.working_from">的每个select会将其数据指向相应的ng-reapeat

明白了?换句话说,您的代码无法按预期工作,因为docSchedule指向每个范围内的同一模型,每个data1.working_from