Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/365.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 未使用angular js填充下拉列表值_Javascript_Angularjs - Fatal编程技术网

Javascript 未使用angular js填充下拉列表值

Javascript 未使用angular js填充下拉列表值,javascript,angularjs,Javascript,Angularjs,我有一个我想要编辑的用户对象,点击编辑按钮,表单的几个值被加载,但三个值没有被填充。我从服务中检查,我正在获取数据,但数据没有填充 <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right"> <label class="control-label">{{::'label.country'|translate}}</label> <label class

我有一个我想要编辑的用户对象,点击编辑按钮,表单的几个值被加载,但三个值没有被填充。我从服务中检查,我正在获取数据,但数据没有填充

    <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
        <label class="control-label">{{::'label.country'|translate}}</label>
        <label class="asterisk">*</label>
    </div>
    <div class="col-xs-8 col-sm-8 col-md-9 col-lg-9 controls">
        <select id="selectCountry" name="selectCountry" required ui-select2="select2CountrySettings" ng-model="selectedUser.country">
            <option ng-repeat="country in countryList" value="{{country.name}}" ng-selected="{{country.name == selectedUser.country}}">{{country.name}}</option>
        </select>
        <span class="help-block" ng-show="editUserForm.selectCountry.$dirty && editUserForm.selectCountry.$error.required">{{::'error.required'|translate}}</span>
    </div>
</div>

<!-- Locale -->
<div class="row control-group" ng-class="{error:editUserForm.selectLocale.$dirty && !editUserForm.selectLocale.$valid, success:editUserForm.selectLocale.$valid}">

    <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
        <label class="control-label">{{::'label.user.locale'|translate}}</label>
        <label class="asterisk">*</label>
    </div>
    <div class="col-xs-7 col-sm-7 col-md-9 col-lg-9 controls">
        <select id="selectLocale" name="selectLocale" required class="locale-select" ui-select2="select2LocaleSettings" ng-model="selectedUser.culture">
            <option ng-repeat="locale in localeList" value="{{locale.name}}" ng-selected="{{locale.name == selectedUser.culture}}">{{locale.name}}</option>
        </select>
        <span class="help-block" ng-show="editUserForm.selectLocale.$dirty && editUserForm.selectLocale.$error.required">{{::'error.required'|translate}}</span>
    </div>
</div>
HTML

    <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
        <label class="control-label">{{::'label.country'|translate}}</label>
        <label class="asterisk">*</label>
    </div>
    <div class="col-xs-8 col-sm-8 col-md-9 col-lg-9 controls">
        <select id="selectCountry" name="selectCountry" required ui-select2="select2CountrySettings" ng-model="selectedUser.country">
            <option ng-repeat="country in countryList" value="{{country.name}}" ng-selected="{{country.name == selectedUser.country}}">{{country.name}}</option>
        </select>
        <span class="help-block" ng-show="editUserForm.selectCountry.$dirty && editUserForm.selectCountry.$error.required">{{::'error.required'|translate}}</span>
    </div>
</div>

<!-- Locale -->
<div class="row control-group" ng-class="{error:editUserForm.selectLocale.$dirty && !editUserForm.selectLocale.$valid, success:editUserForm.selectLocale.$valid}">

    <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
        <label class="control-label">{{::'label.user.locale'|translate}}</label>
        <label class="asterisk">*</label>
    </div>
    <div class="col-xs-7 col-sm-7 col-md-9 col-lg-9 controls">
        <select id="selectLocale" name="selectLocale" required class="locale-select" ui-select2="select2LocaleSettings" ng-model="selectedUser.culture">
            <option ng-repeat="locale in localeList" value="{{locale.name}}" ng-selected="{{locale.name == selectedUser.culture}}">{{locale.name}}</option>
        </select>
        <span class="help-block" ng-show="editUserForm.selectLocale.$dirty && editUserForm.selectLocale.$error.required">{{::'error.required'|translate}}</span>
    </div>
</div>
$scope.selectedUser
中,我将从服务最后三个下拉列表中获取所有值。区域设置、国家/地区和组织未在下拉列表中填充

    <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
        <label class="control-label">{{::'label.country'|translate}}</label>
        <label class="asterisk">*</label>
    </div>
    <div class="col-xs-8 col-sm-8 col-md-9 col-lg-9 controls">
        <select id="selectCountry" name="selectCountry" required ui-select2="select2CountrySettings" ng-model="selectedUser.country">
            <option ng-repeat="country in countryList" value="{{country.name}}" ng-selected="{{country.name == selectedUser.country}}">{{country.name}}</option>
        </select>
        <span class="help-block" ng-show="editUserForm.selectCountry.$dirty && editUserForm.selectCountry.$error.required">{{::'error.required'|translate}}</span>
    </div>
</div>

<!-- Locale -->
<div class="row control-group" ng-class="{error:editUserForm.selectLocale.$dirty && !editUserForm.selectLocale.$valid, success:editUserForm.selectLocale.$valid}">

    <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
        <label class="control-label">{{::'label.user.locale'|translate}}</label>
        <label class="asterisk">*</label>
    </div>
    <div class="col-xs-7 col-sm-7 col-md-9 col-lg-9 controls">
        <select id="selectLocale" name="selectLocale" required class="locale-select" ui-select2="select2LocaleSettings" ng-model="selectedUser.culture">
            <option ng-repeat="locale in localeList" value="{{locale.name}}" ng-selected="{{locale.name == selectedUser.culture}}">{{locale.name}}</option>
        </select>
        <span class="help-block" ng-show="editUserForm.selectLocale.$dirty && editUserForm.selectLocale.$error.required">{{::'error.required'|translate}}</span>
    </div>
</div>
  • 使用ng选项,它将在“选择”框中显示选定项
  • 如何使用它

        <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
            <label class="control-label">{{::'label.country'|translate}}</label>
            <label class="asterisk">*</label>
        </div>
        <div class="col-xs-8 col-sm-8 col-md-9 col-lg-9 controls">
            <select id="selectCountry" name="selectCountry" required ui-select2="select2CountrySettings" ng-model="selectedUser.country">
                <option ng-repeat="country in countryList" value="{{country.name}}" ng-selected="{{country.name == selectedUser.country}}">{{country.name}}</option>
            </select>
            <span class="help-block" ng-show="editUserForm.selectCountry.$dirty && editUserForm.selectCountry.$error.required">{{::'error.required'|translate}}</span>
        </div>
    </div>
    
    <!-- Locale -->
    <div class="row control-group" ng-class="{error:editUserForm.selectLocale.$dirty && !editUserForm.selectLocale.$valid, success:editUserForm.selectLocale.$valid}">
    
        <div class="col-xs-4 col-sm-4 col-md-3 col-lg-3 label-right">
            <label class="control-label">{{::'label.user.locale'|translate}}</label>
            <label class="asterisk">*</label>
        </div>
        <div class="col-xs-7 col-sm-7 col-md-9 col-lg-9 controls">
            <select id="selectLocale" name="selectLocale" required class="locale-select" ui-select2="select2LocaleSettings" ng-model="selectedUser.culture">
                <option ng-repeat="locale in localeList" value="{{locale.name}}" ng-selected="{{locale.name == selectedUser.culture}}">{{locale.name}}</option>
            </select>
            <span class="help-block" ng-show="editUserForm.selectLocale.$dirty && editUserForm.selectLocale.$error.required">{{::'error.required'|translate}}</span>
        </div>
    </div>
    
    ng-options="item.id as item.name for item in names"
    
  • 使用ng if将值指定给相应的模型

  • 您能否只包含代码的相关部分,而不是100行HTML代码?可能您返回的数据与您在选择列表中设置为值的数据不同?我得到的答案是,我的数据在解析承诺之前已填充。