我正在尝试显示作为 ArrayList 响应传递的对象数据。我能够看到对象的内容,但无法在 angularjs View 中使用它。 这是我的 Spring Controller 方法:
@RequestMapping(value = "/page2", method = RequestMethod.POST)
public @ResponseBody ArrayList<ConceptModelDetails> getAllTasks() {
ArrayList<ConceptModelDetails> list = new ArrayList<ConceptModelDetails>();
ApplicationContext context = new ClassPathXmlApplicationContext(
"Spring-module.xml");
JDBCConceptModelDAO objDAO = (JDBCConceptModelDAO) context
.getBean("objDAO");
list = objDAO.getData();
return list;
}
这是 View 页面2
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.mi n.js"></script>
</head>
<body>
<form action="page2" method="post">
<h1>
Success: <input type="submit" value="See Data">
</h1>
</form>
<div ng-app="myApp" ng-controller="controller">
<table>
<tr ng-repeat="x in object">
<td>${ x.requestor }</td>
</tr>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('controller', function($scope, $http) {
$http.post("page2")
.success(function(response) {
$scope.object = response.records;
console.log(response);
});
});
</script>
单击“查看数据”后,我得到以下输出:
但我想在表格中显示数据。
最佳答案
response
对象只是一个 JavaScript 对象数组。然后您可以将其绑定(bind)到 ngGrid组件来渲染它。
在 HTML 中:
<body ng-controller="MyCtrl">
<div class="gridStyle" ng-grid="gridOptions">
</div>
</body>
在 JavaScript 中:
$scope.conceptModelDetailsList = response;
$scope.gridOptions = { data: 'conceptModelDetailsList' };
请注意,这只是一种方法。有很多不同的方式来呈现这样的列表。
关于java - 如何在 Angularjs 中使用 Spring Controller 的响应对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33751846/