-1
以獲得ID相同的JSON陣列中的另一個對象在填寫表格我發送closedBy
所選項目的id這樣如何使用angularjs
if (selectedClosedPlaces != undefined) {
place.closedBy = selectedClosedPlaces.map(function(g) {
return g._id;
});
} else {
place.closedBy = ['no_name'];
}
我使用{{發生在HTML顯示它。 closedBy}}。
我將有JSON數據這樣
[{"_id":"56bc720bd0113ab80dd3cb2d","name":{"en":"fshu","de":"hfasj"},"closedBy":["no_name"],"category":{"_id":"56bb2999f197db040dc3b12b","name":{"en":"asdfdsf","de":"asdf"}}}},
{"_id":"56bc7238d0113ab80dd3cb2e","name":{"en":"jsfadk","de":"jkgdj"},"closedBy":["56bc720bd0113ab80dd3cb2d"],"category":{"_id":"56bb2999f197db040dc3b12b","name":{"en":"asdfdsf","de":"asdf"}}}}]
對於第一個將是空的,所以我給了一些名稱,比如['no_name']
。添加第一個之後,我只能使用selectbox選擇closedBy。
現在我退回第二個ID。我有第二個封閉的ID使用,請檢查上面的JSON。與該ID我需要獲取該名稱
例如:我有56bc720bd0113ab80dd3cb2d
身份證與此ID我需要顯示name.en和name.de =>fshu and hfasj
。 我使用服務來獲得價值
這裏 //服務代碼
.service('PlaceService', function($http) {
return {
init: function(callback) {
$http.get('/api/places').then(function(place_response) {
callback(place_response);
});
}
}
})
和控制器
PlaceService.init(function(place_response) {
$scope.places = place_response.data;
console.log($scope.places); //giving all the places details like the //above json.
console.log($scope.places.closedBy); // Not giving closedBy value here
任何人都可以請幫我
讀過這3次並不能找出你所問的 – charlietfl
如果我得到**(selectedClosedPlaces =未定義!){ place.closedBy = selectedClosedPlaces。圖(函數(g)){g0_12; }); } else { place.closedBy = ['no_name']; } ** 我得到_id這個JavaScript代碼,我需要顯示name.en和name.de與我得到的特定ID – codelearner