簡體   English   中英

AngularJS <select>不能在對象中保存價值?

[英]AngularJS <select> not saving value in object?

我在代表一個項目的行中有這個選擇元素(可以有幾個)。 但是,選擇此選項后,制造商的范圍不會更新。 該項目的制造商屬性的默認值為null(自創建以來-尚未選擇任何制造商)

<select ng-model="manufacturer" ng-options="manufacturers.name for manufacturers in manufacturers" ng-change="change()" class="ng-valid ng-dirty">
<option value="" selected="selected" class=""> --Select a Manufacturer--</option>
<option value="0">Choice1</option>
<option value="1">Choice2</option>
<option value="2">Choice3</option>
</select>

我想我的問題是-如何在項目中獲取制造商屬性以使用選擇框進行更新?

謝謝!

如果有幫助-這是cams項目的范圍:

$scope.cams = [
    {channels:1, manufacturer:null},
    {channels:1, manufacturer:null}
    ];

原來ng-model="manufacturer"應該是ng-model="cam.manufacturer"

<select ng-model="cam.manufacturer" ng-options="manufacturers.name for manufacturers in manufacturers" ng-change="change()" class="ng-valid ng-dirty">
<option value="" selected="selected" class=""> --Select a Manufacturer--</option>
<option value="0">Choice1</option>
<option value="1">Choice2</option>
<option value="2">Choice3</option>
</select>

現在,它可以完美運行了。

您可以使用此:

HTML
<selectmultiple ng-model="selectedValues">
    <option ng-repeat="lang inLanguages" value="{{lang.name}}" ng-click="selected(selectedValues)">{{lang.name}}</option>
</select>

angularjs:

$scope.selected = function(nowSelected){
    $scope.selectedValues = [];
    if( ! nowSelected ){
        return;
    }
    angular.forEach(nowSelected, function(val){
        $scope.selectedValues.push(val);
    });
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM