代码之家  ›  专栏  ›  技术社区  ›  rosu alin

javascript angularJS<select>的默认值为0,此时应为1。

  •  0
  • rosu alin  · 技术社区  · 6 年前

    这是我的HTML代码:

          <table>
              <div ng-repeat="product in products" value="{{product}}">
                 <div id="order_beacon" style="display: inline-flex; width: 100%;" class="row">
                     <span class="beacon_quantity">Quantity
                        <select id="beacon_count"  class="beacon_count"  ng-model="product.quantity">
                            <option ng-repeat="option in quantityOptions" value="{{option}}">{{option}}</option>
                        </select>
                     </span>
                 </div>
              </div>
          </table>
    

    在我的JS中,我从服务器中得到了产品列表,甚至硬编码所有产品,使数量为1。

      for (var j = 0; j < $scope.productsAll.length; j++) {
        $scope.productsAll[j].quantity = 1;
    }
    

    如您所见,我的select标签将ng模型设置为product.quantity。那么,不应该将默认值设置为这个值吗?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Chaminda Jayanath Udawatte    6 年前
    <table>
              <div ng-repeat="product in products" value="{{product}}">
                 <div id="order_beacon" style="display: inline-flex; width: 100%;" class="row">
                     <span class="beacon_quantity">Quantity
                        <select id="beacon_count"  class="beacon_count"  ng-model="product.quantity" ng-options="b as b for b in quantityOptions">
    
                        </select>
                     </span>
                 </div>
              </div>
          </table>