我是AngularJS的新手。现在,我在一个电子商务站点上应用了以下两个过滤器:
<div ng-show="user.ShipMethod != null && shippers && orderShipAddress.AddressName != 'BIG'" " ng-class="{'view-form-select': !currentOrder.LineItems[0].ShipperName, '': currentOrder.LineItems[0].ShipperName }">
<label ng-class="{required: !currentOrder.IsMultipleShip() && user.ShipMethod != null}" ng-show="currentOrder.LineItems[0].ShipperName || !currentOrder.IsMultipleShip() && user.ShipMethod != null">{{('Shipping' | r) + ' Method' | xlat}}</label>
<select class="form-control" ng-change="updateShipper()" name="shipMethod"
ng-model="currentOrder.LineItems[0].ShipperName"
ng-show="user.ShipMethod.ShipperSelectionType == 'UserDropDown'"
ng-options="shipper.Name as (shipper.Name + ' ' + (shipper.ShippingRate.Price | currency | xlat)) for shipper in shippers | filter: { Name: '!Pick-Up at BIG'}"
ng-required="!currentOrder.IsMultipleShip() && user.ShipMethod != null" >
<option value=""></option>
</select>
<i class="fa fa-truck"></i>
</div>
<div ng-show="user.ShipMethod != null && shippers && orderShipAddress.AddressName == 'BIG'" ng-class="{'view-form-select': !currentOrder.LineItems[0].ShipperName, '': currentOrder.LineItems[0].ShipperName }">
<label ng-class="{required: !currentOrder.IsMultipleShip() && user.ShipMethod != null}" ng-show="currentOrder.LineItems[0].ShipperName || !currentOrder.IsMultipleShip() && user.ShipMethod != null">{{('Shipping' | r) + ' Method' | xlat}}</label>
<select class="form-control" ng-change="updateShipper()" name="shipMethod"
ng-model="currentOrder.LineItems[0].ShipperName"
ng-show="user.ShipMethod.ShipperSelectionType == 'UserDropDown'"
ng-options="shipper.Name as (shipper.Name + ' ' + (shipper.ShippingRate.Price | currency | xlat)) for shipper in shippers | filter: { Name: 'Pick-Up at BIG'}"
ng-required="!currentOrder.IsMultipleShip() && user.ShipMethod != null" >
<option value=""></option>
</select>
<i class="fa fa-truck"></i>
</div>
</div>我的控制器位于这里:https://big.four51ordercloud.com/test0530/js/directives/ordershipping.js
在我的控制器中,我想出了这个方法来设置默认的下拉菜单选项,但是我不知道将它放在updateShipper()函数中的位置。如果下拉菜单中只有一个选项,我希望它默认。现在,如果有一个选项,用户必须手动选择它,但是,其他选项可以填充,这取决于是否满足了其他筛选器的条件。你看到的第一个过滤器总是在下拉菜单中产生多个选项,而第二个过滤器总是只产生一个选项--“大拾取”选项。
$scope.currentOrder.LineItems[0].ShipperName = $scope.shippers[0];发布于 2015-06-13 17:34:13
使用ng-模型为列表项设置默认值。每当您选择一项时,您所设置的ng模型变量将更新。
请参阅示例
<select ng-options="p for p in animal"
ng-model="selectedanimal"></select>https://stackoverflow.com/questions/30821022
复制相似问题