我是这个领域的新手(一个月),我正在使用 angularJs 开发应用程序,我正在收到带有列表的 Json 申请,我必须输入名称 ({{empresa. name }}
),当用户选择时,我得到 ID({{empresa.IdEmpresa}}
)。
我想使用 ng-repeat 来实现这一点,例如(ng-repeat="empresa in empresas"
)。
我从 JavaController 中获取带有列表的 Json,我的实体名为 Empresa,我在 Angular 上声明一个空对象($scope.empresas = {}
)并给出回调这个空对象,对吗?!
我的选择字段是这样的
<label>Empresa</label>
<select class="form-control">
<option value="{{empresa.EmpresaId}}">{{empresa.name}}</option>
</select>
如何在其中使用重复?
最佳答案
假设您的 JSON 数据如下所示
$scope.empresas = [
{ EmpresaId: 1, name: 'one' },
{ EmpresaId: 2, name: 'two' },
{ EmpresaId: 3, name: 'three' }
]
除了使用 ng-repeat
上<options>
,您还可以使用ng-options
<select ng-options="e.EmpresaId as e.name for e in empresas" ng-model="???"></select>
关于javascript - 使用 AngularJs 使用 Json 回调填充 Select 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38151403/