我有什麼似乎是一個簡單的問題,AngularJS - 如果是這樣的道歉。我是新來的,已經搜遍遍地,無法完全找到我想要做的事情的答案。AngularJS - NG-重複 - 用孩子的HTTP請求父重複數據
基本上我有一個是我從中再使用NG-重複建設的HTML服務器得到「卡」列表的$ HTTP請求。然後,我想用一些「度量標準」來填充這些卡片 - 也從服務器中檢索。我有一個'卡'(父母)的控制器和'度量'(兒童)的單獨控制器。
我的問題是,我無法工作,如何讓孩子$ HTTP請求時,引用父「卡」的ID。
下面是HTML & JS,我使用 - 任何幫助將appriciated:
HTML:
<div class="Dashboard container-fluid" ng-controller="DahsboardCardController as Dashboard">
<div ng-repeat="Card in Dashboard.DashboardCards">
<div class="DashboardCard card">
{{Card.CardDisplayName}}
<div class="DashboardCardBody" ng-controller="DahsboardMetricController as Metric">
<div ng-repeat="Metric in Metric.DashboardMetrics">
{{Metric.MetricDisplayName}}
</div>
</div>
</div>
</div>
JS:
(function() {
var app = angular.module('OtterDashboard', [ ]);
app.controller('DahsboardCardController', [ '$http', function($http) {
//Declare a varaible for the data
var DashboardCards = this;
//Set the varaiable to an empty array to receive the data
DashboardCards.DashboardCards = [ ];
$http({
//Request the data
method: 'GET',
dataType: 'jsonp',
url: '/api.svc/tbl_Card',
useDefaultXhrHeader: false,
headers: {'Content-type': 'application/json'},
headers: {'Accept': 'application/json;odata=light;q=1,application/json;odata=verbose;q=0.5'},
crossDomain: true,
}).then(function successCallback(data) {
//The data was sucessfully received, populate the variable with it
DashboardCards.DashboardCards = data.data.d.results;
}, function errorCallback(response) {
//There was an error
console.log('Card data could not be retrieved');
});
}]);
app.controller('DahsboardMetricController', ['$http', function($http, Card) {
//Declare a varaible for the data
var DashboardMetrics = this;
//Set the varaiable to an empty array to receive the data
DashboardMetrics.DashboardMetrics = [ ];
$http({
//Request the data
method: 'GET',
dataType: 'jsonp',
url: '/api.svc/DashboardMetric?Card=%27' + **???reference to parent card ID???** + '%27',
useDefaultXhrHeader: false,
headers: {'Content-type': 'application/json'},
headers: {'Accept': 'application/json;odata=light;q=1,application/json;odata=verbose;q=0.5'},
crossDomain: true,
}).then(function successCallback(data) {
//The data was sucessfully received, populate the variable with it
DashboardMetrics.DashboardMetrics = data.data.d.results;
}, function errorCallback(response) {
//There was an error
console.log('Metric data could not be retrieved');
});
}]);
})();
謝謝!
可以簡化這個我們呢?刪除所有不匹配的代碼 –
感謝您的及時回覆本。我已經減少了HTML,對不起。我認爲JS中的一切都是必需的。 –
不知道你的卡結構是什麼我猜Card.id或Card.CardID?實際上,你可以上傳你的儀表板JSON – Jax