javascript - Angular js,关于ng-change如何更新其他选择控件的选项

标签 javascript php jquery angularjs

在更改年份值时,我想更改 Make 下拉列表的选项,但不知道如何更新其他控件的选项。

下面是我的表格。 https://plnkr.co/edit/aV65Nab9U9I6YlK2g4sY?p=preview
api.php 是服务器响应,这些选项应在年份更改时显示在“Make”下拉列表中。

autoQuoteCtrl.js

$scope.updateMakeList = function(){
}

index.html

 <div class="row">
                    <div class="form-group">
                        <label class="col-sm-5 control-label" for="PC">{{questions[$state.current.name].VehicleYear.QuestionData._text}}</label>
                        <div class="col-sm-6">
                            <select ng-change="updateMakeList" custom-required="true" ng-options="ans._value as ans._promptText for ans in questions[$state.current.name].VehicleYear.QuestionData._answerOptions" ng-model="answers.VehicleYear" ng-required="queObj._required" class="form-control {{queObj._pageAttributes.cssclass}}" name="{{questions[$state.current.name].VehicleYear.QuestionData._attributeName}}" id="{{questions[$state.current.name].VehicleYear.QuestionData._attributeName}}" data-que-obj="questions[$state.current.name].VehicleYear.QuestionData" select-control-dir setMake custom-required></select>
                        </div>                    
                    </div>
                    <span class="form-error" ng-show="submitted && DTOstep1.VehicleYear.$error.required">This field is required.</span>
                </div>

最佳答案

您需要将此功能放入您的 Controller 中 -

    $scope.updateMakeList = function(name)
                    {                
// Your logic to change value in Make dropdown
$scope.questions[name].VehicleMake.QuestionData._answerOptions = [{'_value':"test",'_promptText':"Test"}];
                    }

并更新您的 HTML(年份选择框)-

            <div class="form-group">
                <label class="col-sm-5 control-label" for="PC">{{questions[$state.current.name].VehicleYear.QuestionData._text}}</label>
                <div class="col-sm-6">
                    <select ng-change="updateMakeList($state.current.name)" custom-required="true" ng-options="ans._value as ans._promptText for ans in questions[$state.current.name].VehicleYear.QuestionData._answerOptions" ng-model="answers.VehicleYear" ng-required="queObj._required" class="form-control {{queObj._pageAttributes.cssclass}}" name="{{questions[$state.current.name].VehicleYear.QuestionData._attributeName}}" id="{{questions[$state.current.name].VehicleYear.QuestionData._attributeName}}" data-que-obj="questions[$state.current.name].VehicleYear.QuestionData" select-control-dir setMake custom-required></select>
                </div>                    
            </div>

关于javascript - Angular js,关于ng-change如何更新其他选择控件的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38911925/

相关文章:

PHP无需等待即可执行外部脚本,同时传递变量

php - 如何评估来自 jQuery $.get 的数据返回 bool 值

jquery - 在jqGrid中,可以双击一行来弹出编辑表单吗?

javascript - 高速路由器

javascript - 与 Firefox 的链接问题

PHP序列化函数-将序列化后的数据添加到mysql中,然后获取并显示

javascript - 在 jquery 中访问 angular2 变量

javascript - 在数组中搜索对象属性,然后隐藏第一次出现的找到的对象

javascript - angularjs fullcalendar eventclick范围

javascript - 如何使用 Leaflet 通过缩放更改 geojson 中的图标?