【发布时间】:2015-03-05 11:27:45
【问题描述】:
问题:我有一个网格,我为其实现了创建和更新功能。在创建时,用户会得到一个模式对话框,其中包含一些字段和一些下拉列表(每个下拉列表都填充了来自数据库的数据)。
我遇到的问题是更新。如果用户想要从网格更新记录,他将选择行并单击一个按钮,该按钮将打开一个模式对话框,以“不可编辑模式”显示所有记录字段。只有当用户单击模式对话框底部的“编辑”按钮时,这些字段才会变得可编辑。 问题是:如何让下拉列表(即国家/地区列表)以“不可编辑模式”(例如爱尔兰)仅显示该特定记录的数据,并且一旦用户单击“编辑按钮”下拉菜单仍显示相同的数据(爱尔兰)。除非用户单击下拉菜单,然后该下拉菜单将显示整个国家/地区列表,因此最终可以选择不同的国家/地区。
为了举例,我将发布国家下拉列表的当前实现。这是我在创建模式对话框中使用的代码,对于更新模式对话框,它应该是类似的,但不知道如何从网格中显示所选记录的相关国家。
填充国家/地区下拉列表
<div class="control-group">
<label class="control-label">*Country</label>
<div class="input-append">
<div data-ng-init="getCountryDataFromServer()">
<b>Person Data:</b> <select id="countryId" ng-model="contact.countryId">
<option value="">-- Select Countries --</option>
<option data-ng-repeat="country in countries" value="{{country.countryId}}">{{country.countryname}}</option>
</select><br>
</div>
</div>
<div class="input-append">
<label>
<span class="alert alert-error"
ng-show="displayValidationError && newContactForm.countryData.$error.required">
<spring:message code="required"/>
</span>
</label>
</div>
</div>
Ng-Init Angularjs 指令
//Load countries from JSON and populate the dropdown
$scope.getCountryDataFromServer = function() {
$http({method: 'GET', url: '/tool/protected/country/all'}).
success(function(data, status, headers, config) {
$scope.countries = data;
}).
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
};
【问题讨论】:
标签: angularjs spring-mvc angularjs-directive