Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.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 编辑名称时,在AngularJS中的下拉菜单上显示相同的名称项_Javascript_Angularjs_Html_Drop Down Menu - Fatal编程技术网

Javascript 编辑名称时,在AngularJS中的下拉菜单上显示相同的名称项

Javascript 编辑名称时,在AngularJS中的下拉菜单上显示相同的名称项,javascript,angularjs,html,drop-down-menu,Javascript,Angularjs,Html,Drop Down Menu,我有一个连接到数据库的简单AngularJS表单 该表单在HTML表格中显示姓名和出生国列表: <table class="table table-bordered" style="max-width: 100%;" id="myAreas"> <tr ng-repeat="name in Names"> <td>{{name.FullName}}</td> <td>

我有一个连接到数据库的简单AngularJS表单

该表单在HTML表格中显示姓名和出生国列表:

<table class="table table-bordered" style="max-width: 100%;" id="myAreas">
    <tr ng-repeat="name in Names">
        <td>{{name.FullName}}</td>
        <td>                               
            <select ng-model="selectedCountryForEdit" ng-show="editMode">
                <option ng-repeat="z in countryList" value="{{z.CountryCode}}">{{z.CountryName}}</option>
            </select>
            <span style="display: block;" ng-show="!editMode">{{areaItem.Countries}}</span>
        </td>                            
        <td><a href="" ng-click="editMode = !editMode"><i class="fa fa-pencil" aria-hidden="true"></i></a></td>
    </tr>                    
</table>
JS/Angular正在MVC上调用一个方法来列出数据库中的数据

我不想包含MVC代码,因为它工作正常,我的问题依赖于其他方面:

如果看html表格,每行都有一个铅笔图标,允许我显示一个下拉菜单,而不是国家

我所做的是用数据库中的国家列表填充下拉菜单,我希望下拉菜单显示所选行/名称的相同国家


我搜索了很多,找不到如何解决这个问题。我对Angular和JS非常陌生,希望您能就此提供建议

您需要将select的
ng model
更改为
Names
数组中的属性。 例如,如果名称具有att country,则
ng型号
将与
名称
相同

<table class="table table-bordered" style="max-width: 100%;" id="myAreas">
    <tr ng-repeat="name in Names">
        <td>{{name.FullName}}</td>
        <td>                               
            <select ng-model="name.country" ng-show="editMode">
                <option ng-repeat="z in countryList" value="{{z.CountryCode}}">{{z.CountryName}}</option>
            </select>
            <span style="display: block;" ng-show="!editMode">{{areaItem.Countries}}</span>
        </td>                            
        <td><a href="" ng-click="editMode = !editMode"><i class="fa fa-pencil" aria-hidden="true"></i></a></td>
    </tr>                    
</table>

{{name.FullName}
{{z.CountryName}
{{areaItem.Countries}
还将建议将te select选项ng repeat更改为ng选项,因为此选项具有更好的性能

例如:

<select ng-model="name.country" ng-show="editMode" ng-options="z.countryCode as z.CountryName for z in countryList">
    <option value="">Select...</option>
 </select>

选择

谢谢!我会试试看,然后再打给你
<select ng-model="name.country" ng-show="editMode" ng-options="z.countryCode as z.CountryName for z in countryList">
    <option value="">Select...</option>
 </select>