[英]repeats array in json/angularjs
我試圖做一個日歷,在AngularJS的請求resto中可以獲取信息。 我想創建一個日歷,您可以在其中注冊事件。 使用json屬性的日期,它可以輸入此事件並在當天注冊一個圖標。
我的錯誤是,如您在圖片中看到的,它將獲取一個數組並插入所有字段,而不僅是在注冊到json的那一天。 我的工作重復了42次,這是日歷上的平方數。 沒有人知道我的方法的錯誤之處是我不理解。
圖片
控制者
$scope.setDayContent = function(date) {
return $http ({
method : "GET",
url : "app/components/home/controller/test_calendar.json"
}).then(function mySucces(response) {
return response.data.data[0].title;
}, function myError(response) {
$scope.valor = response.statusText;
});
};
json
{"data":[
{"title":"John",
"start":"2016-10-22"
}, {
"title":"Richard",
"start":"2016-10-25"
}
]}
html
<calendar-md flex layout layout-fill
calendar-direction="direction"
on-prev-month="prevMonth"
on-next-month="nextMonth"
on-day-click="dayClick"
ng-model='selectedDate'
week-starts-on="firstDayOfWeek"
tooltips="tooltips"
day-format="dayFormat"
day-content="setDayContent"
></calendar-md>
您的函數setDateContent
針對日歷中的每個日期運行。 在success
回調中,您需要添加邏輯以檢查返回的數據並設置變量或返回當天所需的信息。
您不應該每天加載JSON。 您應該加載JSON,然后在函數中檢查每個日期。
$scope.loadData = function(){
return $http ({
method : "GET",
url : "app/components/home/controller/test_calendar.json"
}).then(function mySucces(response) {
$scope.jsonData = response.data;
}, function myError(response) {
$scope.valor = response.statusText;
});
}
$scope.setDayContent = function(date) {
//check if $scope.jsonData contains date parameter
// return title
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.