0
我有AngularJS + SpringMVC項目。 通過GET方法它返回實體列表,所以我可以使用它ng-repeat打印對象數據(名稱,例如) 但最近我需要使用hashmap(鍵 - 對象與字段,值 - 字符串)正確處理SpringMVC中的hashmaps + angularjs
這是代碼的一部分,即i的角度
用於解釋這是如何對象填充字段列表
<input type="text" ng-model="currentItem.taskName" class="form-control">
app.controller('mainController',function ($scope, $http) {
$scope.tasks = [];
$scope.currentItem = {};
$scope.currentView = 'allTasks';
$scope.refresh = function() {
$http({
method:"GET",
url:"/task"
}).then(function (result) {
$scope.tasks = result.data;
});
};
$scope.refresh();
$scope.save = function(){
$http({
method:"PUT",
url:"/task",
data:$scope.currentItem,
headers:{'X-CSRF-TOKEN':$("meta[name='_csrf']").attr("content")}
}).then(function(result) {
for(var i = 0; i < $scope.tasks.length; i++){
if(result.data.id===$scope.tasks[i].id){
$scope.tasks.splice(i, 1);
}
}
$scope.tasks.push(result.data);
});
$scope.cancel();
};
現在我有這個控制器:
@GetMapping
public Map<TaskEntity,String> findAll(){
user = (UserEntity) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
return taskService.findFromUser(user.getId());
}
但它似乎沒有工作。 角找不到對象的領域,當我使用
ng-repeat="(k,v) in tasks" {{k.name}}
但打印此k
作爲對象名稱[email protected]
所以我的問題是:如何正確讀取HashMap和添加項目到它
傑克遜,所以不,我不認爲這是問題。在列表之間它一切都好 – jusinejo