繁体   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