我在前端AngularJS 1.4和后端Java中使用,我有很多选项可以在前端选择,例如,国家:如何在前端处理来自后端的枚举
GERMANY
FRANCE
USA
RUSSIA
枚举以大写字母写,我将在前端对其进行自定义(例如,法国将变为法国)。
我现在的问题是,如果有一个指令或任何其他支持这样做在前端。
我在前端AngularJS 1.4和后端Java中使用,我有很多选项可以在前端选择,例如,国家:如何在前端处理来自后端的枚举
GERMANY
FRANCE
USA
RUSSIA
枚举以大写字母写,我将在前端对其进行自定义(例如,法国将变为法国)。
我现在的问题是,如果有一个指令或任何其他支持这样做在前端。
退房此链接 http://hello-angularjs.appspot.com/angularjs-create-custom-filter
它写它可以帮助您自定义过滤器。
这是上面给出的链接代码。
<!DOCTYPE html>
<html ng-app="HelloApp">
<head>
<title></title>
</head>
<body ng-controller="HelloCtrl">
<form>
<input type="text" ng-model="name"/>
</form>
<div>{\{name|titlecase}}</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script type="text/javascript">
// Code defining custom module consisting of a filter
// The module needs to be included as dependency for using the filter, titlecase
//
angular.module('CustomFilterModule', [])
.filter('titlecase', function() {
return function(input) {
return input.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
});
// Angular App on this page
// Included CustomFilterModule as dependency
//
angular.module('HelloApp', [ 'CustomFilterModule'])
.controller('HelloCtrl', ['$scope', function($scope){
$scope.name = '';
}])
</script>
</body>
</html>
链接可以随时间而打破。更好地将基本部分复制到答案中。只有链接的答案往往也会被低估。 – Fildor
鉴于:
<select ng-model="selectedCountry" ng-options="country as country.name for country in countries | filter:filterUpperCamelCase"></select>
在控制器:
$scope.countries= [
{name:"SPAIN"},
{name:"GERMANY"}
];
$scope.filterUpperCamelCase = function(element){
element.name = element.name.toLowerCase();
element.name = element.name.charAt(0).toUpperCase() + element.name.slice(1);
return element;
};
与价值观 “德国” 给它的成员, '姓名', “法国”,... – Stultuske
你可以编写自己的角度过滤器,或手动映射服务器响应中的值。 – ryanyuyu
你为后端使用什么框架? –