Javascript angularjs <select> 有默认值 0,当它应该是 1
Javascript angularjs <select> has default value 0, when it should be 1
这是我的 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-model 设置为 product.quantity。那么默认值不应该设置成那个吗?
<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>
这是我的 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-model 设置为 product.quantity。那么默认值不应该设置成那个吗?
<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>