我在控制器中有一个像这样的对象:
$scope.organisations = {
"id" : 1,
"name" : "organisation name"
}
和另一个像这样的对象
$scope.region = {
"id" : 1,
"organisation_id" : 1
}
如果organisation.id等于region.organisation_id。
,我想显示选择的组织名称在视图中我使用了这个
<select
ng-options="organisation as organisation.name for organisation in organisations track by organisation.id"
ng-model="region.organisation"
name="organisation_name"
class="form-control">
</select>
现在如何显示在我的区域编辑表单中选择的组织项目?
答案 0 :(得分:0)
试试这个
<select
ng-options="organisation as organisation.name for organisation in organisations track by organisation.id"
ng-model="OrganisationName"
name="organisation_name"
class="form-control">
</select>
控制器应该是
$scope.OrganisationName = $scope.region.organisation_id
//或
$scope.OrganisationName.id = $scope.region.organisation_id
答案 1 :(得分:0)
试试这个:
var app = angular.module("app" , []);
app.controller("appCtrl", appCtrl)
function appCtrl($scope){
$scope.organisations = [{
"id" : 1,
"name" : "organisation name"
},{
"id" : 2,
"name" : "organisation name2"
}]
$scope.region = {
"id" : 1,
"organisation_id" : 1
}
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<div ng-app="app" ng-controller="appCtrl">
<select
ng-options="organisation.id as organisation.name for organisation in organisations"
ng-model="region.id"
name="organisation_name"
class="form-control" ng-selected="{{organisation.Id == region.id}}">
</select>
</div>
&#13;