摘要:select options指令value
select options指令value
<select name="kind" data-ng-model="model.type" style="width: 50%;">
<option ng-repeat="d in data" value="{{d.id}}">{{d.name}}</option>
</select>
js===============================================
var data = [];
$scope.init = function(){
var result = ydd004eService.save('rest/findResourceType', "" , false);
result.then(function(response) {
if(response && response.length > 0){
for(var i=0;i<response.length;i++){
//alert('id=' + i + " :" + response[i].RESOURCE_TYPE_ID);
//alert('name=' + response[i].RESOURCE_TYPE);
data.push({id : response[i].RESOURCE_TYPE_ID, name : response[i].RESOURCE_TYPE});
}
$scope.data = data;
}
});
};
java==========================================
/*
* 使用 execute 的方式執行,傳入 entity 在判斷要查詢單筆或是多筆。
* 要注意網址不要與 key 值的網址重覆。
*/
@RequestMapping(value = "/findResourceType", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public List<Map<String,String>> findResourceType(@RequestBody String ydd004RequestData, Alerter alerter) {
List<Map<String,String>> tarTypeData = new ArrayList<Map<String, String>>();
List<Map<String,Object>> yddResourceType = service.findResourceType();
Map<String,String> mapData = new HashMap<String,String>();
if (!CollectionUtils.isEmpty(yddResourceType)) {
for (Map<String, Object> key : yddResourceType) {
LOGGER.info("ALL : " + key.toString() + " key : " + key.get("RESOURCE_TYPE_ID") + " ----Value : " + key.get("RESOURCE_TYPE"));
mapData = new HashMap<String,String>();
mapData.put("RESOURCE_TYPE_ID", key.get("RESOURCE_TYPE_ID").toString());
mapData.put("RESOURCE_TYPE", key.get("RESOURCE_TYPE").toString());
tarTypeData.add(mapData);
}
}
return tarTypeData;
}
執行結果
<select class="form-control ng-pristine ng-invalid ng-invalid-required" data-ng-model="model.type" data-ng-options="d.id as d.name for d in data track by d.id" name="kind" required="" style="">
<option value="?" selected="selected"></option>
<option value="1">詞彙</option>
<option value="4">檔案</option>
<option value="5">報表</option>
<option value="6">資料表</option>
<option value="7">資料表欄項</option>
<option value="8">WebService</option>
</select>