【发布时间】:2016-12-26 12:18:06
【问题描述】:
我从 java 端得到一个列表,名称为 [Pune, Mumbai, Delhi]。我希望它垂直显示。我怎样才能做到这一点 。我想在 Angular js 中执行此操作,但不知何故,该函数在单击时没有被调用。 我需要的输出 -
Pune
Mumbai
Delhi
控制器 -
@RequestMapping(value = "/home.web", method = RequestMethod.GET, produces = {"application/xml",
"application/json" })
public ModelAndView getUSCity(@RequestParam ("statechoice") String statechoice) {
List<String> msa = new ArrayList<String>();
msa = msaService.getMsaCodes(statechoice);
ModelAndView model = new ModelAndView("Home");
model.addObject("city",msa);
return model;
}
移除 ng 指令后的 jsp Angular -
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.js"></script>
<!-- <script>
var app = angular.module('myApp', []);
function MyController($scope, $http) {
$scope.getPersonDataFromServer = function() {
alert("Hi");
$http({
method : 'GET',
url : 'home.web'
}).success(function(data, status, headers, config) {
alert(data);
$scope.cities=data;
}).error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
};
};
</script>
-->
</head>
<body style="text-align: center;">
<h4>US map</h4>
<div>
<img src="images/usmap.gif" alt="US MAP" width="529" height="334"
border='0' usemap='#usimage' align="middle">
</div>
<div>
<map name='usimage'>
<!--- BEGIN: East --->
<area shape='polygon' coords='489,52,502,31,513,32,518,54,490,71'
href='home.web?statechoice=ME' target="_self" alt='Maine'>
</map>
</div>
<div>
<table border="1" style="margin-top: 20px;">
<tr style="background-color: lightgray;">
<th>Cities</th>
<tr>
<td>${city}</td>
</tr>
</div>
</body>
</html>
div 标签,当我使用 angular ng-repeat 时。
<body style="text-align: center;" data-ng-app="myApp" data-ng-controller="MyController">
<h4 > US map</h4>
<div>
<img src="images/usmap.gif" alt="US MAP" width="529" height="334" border='0' usemap='#usimage' align="middle">
</div>
<div>
<map name='usimage'>
<!--- BEGIN: East --->
<area shape='polygon' coords='489,52,502,31,513,32,518,54,490,71' data-ng-click="getPersonData()" href='home.web?statechoice=ME' target="_self" alt='Maine'>
</map>
</div>
<div>
<table border ="1" style="margin-top: 20px;">
<tr style="background-color:lightgray;">
<th>Cities</th>
<ul>
<li ng-repeat="city in cities">{{city}}</li>
</ul>
</div>
</body>
</html>
更新 - 现在调用函数。但是这些值没有得到更新。
使用路由 -
<script>
var app = angular.module('myApp', ['ngRoute']).
module.config(function($routeProvider){
$routeProvider
.when('/home.web',{
templateUrl: 'Views/Home.jsp',
})
})
function MyController($scope, $http) {
$scope.getPersonData = function() {
$http({
method : 'GET',
url : 'home.web'
}).success(function(data, status, headers, config) {
alert(data);
$scope.cities = data;
}).error(function(data, status, headers, config) {
console.log("error");
// called asynchronously if an error occurs
// or server returns response with an error status.
});
};
};
</script>
【问题讨论】:
-
我想你忘了关闭 tr 标签
-
<ul>不是<tr>的有效子代
标签: html css angularjs spring-mvc