【问题标题】:Multiple array data post through Angular JS通过 Angular JS 发布多个数组数据
【发布时间】:2017-01-13 11:27:59
【问题描述】:

这是 HTML 页面中视图的一部分,用户可以通过它填充数据并将其发送到 api

在表单中有三个参数会传入一个数组,day。不时地。如何在单个数组中传递这三个参数...在角度 JS 中的 jSON 中,我的代码在这里不起作用是代码。 我现在也想知道如何在 HTML/Angular 视图端以这种格式发送数据?

我的(我认为它会工作)Angular Js 代码

  $scope.schedule = [];
                $scope.schedule[0] = $scope.data1.day;
                $scope.schedule[1] = $scope.data1.from_time;
                $scope.schedule[2] = $scope.data1.to_time;

            var dataParam =  {

                                "Schedule":[$scope.data1.schedule]

                              }
         console.log(angular.toJson(dataParam));

HTML 代码

<tr>
                                            <th  scope="col"><input type="checkbox" name="checkbox1" ng-model="data.checkbox1"></th>
                                            <td ng-model="data1.day">Sunday</td>
                                            <td>
                                                <div class="col-md-12 col-sm-6 col-xs-12 form-group has-feedback">
                                                <select  id="user_time_zone" ng-disabled="!data.checkbox1" class="form-control form-group" value="Schedule" name="user_time_zone">
                                                    <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>
                                            <td>
                                                <div class="col-md-12 col-sm-6 col-xs-12 form-group has-feedback">
                                                     <select  id="user_time_zone" ng-disabled="!data.checkbox1" class="form-control  form-group" value="Schedule" name="user_time_zone">
                                                    <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" ng-disabled="!data.checkbox1" class="form-control  form-group" value="Schedule" name="user_time_zone">
                                                    <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>
                                            <td>
                                                <div  class="col-md-12 col-sm-6 col-xs-12 form-group has-feedback">
                                                     <select  id="user_time_zone" ng-disabled="!data.checkbox1" class="form-control  form-group" value="Schedule" name="user_time_zone">
                                                    <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>
                                            <div class="col-md-12 col-sm-6 col-xs-12 form-group has-feedback">
                                            <input type="button" class="btn btn-primary"  value="Add Break" id="btn" ng-disabled="!data.checkbox1">
                                            </td>
                                           </tr>

一小段java代码sn-p

public class Schedule {
private String Working_day;
private List<String> Working_from;
private List<String> working_to; 

........ }

【问题讨论】:

  • 为什么要将它作为数组传递?
  • 您确定 [$scope.data1.schedule] 和 $scope.schedule 具有相同的数据。在这里我没有看到像 $scope.data1.schedule bieng 这样的东西赋予了一些价值。

标签: javascript java angularjs


【解决方案1】:

替换

var dataParam =  {"Schedule":[$scope.data1.schedule]} with
var dataParam =  {"Schedule":$scope.schedule}

【讨论】:

  • 你能告诉我如何通过 html 以这种格式发送数据吗?因为我们只能给一个具有不同参数的数组,但是如果我也必须在星期一发送数据怎么办?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-03
  • 1970-01-01
相关资源
最近更新 更多