在angularJS中更新数组的数据
问题描述:
我想要做的是制作一个简单的应用程序,用户可以在平日里编辑他的可用性。代码工作正常..我从选择框中获取数据,但是当我试图更新星期一数据的问题时,星期二数据也在用星期一**的相同值进行更新(正如您可以在上一个视图中看到的那样)**在angularJS中更新数组的数据
我的数据库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页面,当我试图updatemonday数据和周二的数据也会自动改变我怎样才能解决这个问题,通过角?
答
变化
<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">
因为这样一来,各ng-reapeat
的每个select
将指向它的数据到各自的docSchedule
。
了解了吗?换句话说,你的代码不能按预期工作,因为data1.working_from
指向每个示波器中的相同型号,每个ng-repeat
都指向同一型号。
确定了..已经做到了,谢谢 – adasdasd
,但不知道我是否能够通过与docSchedule.working_from – adasdasd
阵列你可能会审查你的格式化模型的方式。但至少你可以解决这个问题,“改变一个原因改变其他” – daymannovaes