私はAngularJS + SpringMVCプロジェクトを持っています。 GETメソッドではエンティティのリストを返すので、オブジェクトデータ(名前など)を印刷するためにng-repeatに使用できます。 しかし、最近はハッシュマップ(キーオブジェクトとフィールド、値ストリング)を使用する必要がありましたSpringMVC + angularjsの適切なハンドリングハッシュマップ
これは私が角度
に一覧表示するために使用することを、コードの一部であり、これは、オブジェクトが、私はこのコントローラいた
<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]
だから私の質問は:適切にハッシュマップを読んで、それ
にアイテムを追加する方法
ジャクソン、だから、私はそれが問題だとは思わない。リストの間でそれはすべてOKです – jusinejo