我正在尝试使用matt lewis的角度引导程序日历block
- 使用数据库数据,但我正在尝试几乎每个JSON post,echo,stringify,parse,serialize和等等。
我可以让日历显示带有硬编码字符串的事件,但是当我尝试使用$ http.get获取字符串时,它不会起作用。我竭尽全力确保这个字符串与硬编码字符串相同,但仍然没有。我知道这是很多代码,但我不知道如何显示我的问题。请帮忙!
<!doctype tml ng-app="mwl.calendar.docs">
<head>
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.1/moment.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/interact.js/1.2.4/interact.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-animate.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/2.0.0/ui-bootstrap-tpls.min.js"></script>
<script src="//cdn.rawgit.com/jkbrzt/rrule/v2.1.0/lib/rrule.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular-bootstrap-colorpicker/3.0.25/js/bootstrap-colorpicker-module.min.js"></script>
<script src="//mattlewis92.github.io/angular-bootstrap-calendar/dist/js/angular-bootstrap-calendar-tpls.min.js"></script>
<script src="app/calendarappBk2.js"></script>
<script src="helpers.js"></script>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="//cdnjs.cloudflare.com/ajax/libs/angular-bootstrap-colorpicker/3.0.25/css/colorpicker.min.css" rel="stylesheet">
<link href="//mattlewis92.github.io/angular-bootstrap-calendar/dist/css/angular-bootstrap-calendar.min.css" rel="stylesheet">
</head>
<body>
<div ng-controller="KitchenSinkCtrl as vm">
<h2 class="text-center">{{ vm.calendarTitle }}</h2>
<div class="row">
<div class="col-md-6 text-center">
<div class="btn-group">
<button
class="btn btn-primary"
mwl-date-modifier
date="vm.viewDate"
decrement="vm.calendarView">
Previous
</button>
<button
class="btn btn-default"
mwl-date-modifier
date="vm.viewDate"
set-to-today>
Today
</button>
<button
class="btn btn-primary"
mwl-date-modifier
date="vm.viewDate"
increment="vm.calendarView">
Next
</button>
</div>
</div>
<br class="visible-xs visible-sm">
<div class="col-md-6 text-center">
<div class="btn-group">
<label class="btn btn-primary" ng-model="vm.calendarView" uib-btn-radio="'year'">Year</label>
<label class="btn btn-primary" ng-model="vm.calendarView" uib-btn-radio="'month'">Month</label>
<label class="btn btn-primary" ng-model="vm.calendarView" uib-btn-radio="'week'">Week</label>
<label class="btn btn-primary" ng-model="vm.calendarView" uib-btn-radio="'day'">Day</label>
</div>
</div>
</div>
<br>
<mwl-calendar
events="vm.events"
view="vm.calendarView"
view-title="vm.calendarTitle"
view-date="vm.viewDate"
on-event-click="vm.eventClicked(calendarEvent)"
on-event-times-changed="vm.eventTimesChanged(calendarEvent); calendarEvent.startsAt = calendarNewEventStart; calendarEvent.endsAt = calendarNewEventEnd"
cell-is-open="vm.isCellOpen"
day-view-start="06:00"
day-view-end="22:59"
day-view-split="30"
cell-modifier="vm.modifyCell(calendarCell)">
</mwl-calendar>
<br><br><br>
<h3 id="event-editor">
Edit events
<button
class="btn btn-primary pull-right"
ng-click="vm.addEvent()">
Add new
</button>
<div class="clearfix"></div>
</h3>
<table class="table table-bordered">
<thead>
<tr>
<th>Title</th>
<th>Primary color</th>
<th>Secondary color</th>
<th>Starts at</th>
<th>Ends at</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="event in vm.events track by $index">
<td>
<input
type="text"
class="form-control"
ng-model="event.title">
</td>
<td>
<input class="form-control" colorpicker type="text" ng-model="event.color.primary">
</td>
<td>
<input class="form-control" colorpicker type="text" ng-model="event.color.secondary">
</td>
<td>
<p class="input-group" style="max-width: 250px">
<input
type="text"
class="form-control"
readonly
uib-datepicker-popup="dd MMMM yyyy"
ng-model="event.startsAt"
is-open="event.startOpen"
close-text="Close" >
<span class="input-group-btn">
<button
type="button"
class="btn btn-default"
ng-click="vm.toggle($event, 'startOpen', event)">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</p>
<div
uib-timepicker
ng-model="event.startsAt"
hour-step="1"
minute-step="15"
show-meridian="true">
</div>
</td>
<td>
<p class="input-group" style="max-width: 250px">
<input
type="text"
class="form-control"
readonly
uib-datepicker-popup="dd MMMM yyyy"
ng-model="event.endsAt"
is-open="event.endOpen"
close-text="Close">
<span class="input-group-btn">
<button
type="button"
class="btn btn-default"
ng-click="vm.toggle($event, 'endOpen', event)">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
</p>
<div
uib-timepicker
ng-model="event.endsAt"
hour-step="1"
minute-step="15"
show-meridian="true">
</div>
</td>
<td>
<button
class="btn btn-danger"
ng-click="vm.events.splice($index, 1)">
Delete
</button>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
<?php
$DB_HOST = 'localhost';
$DB_USER = 'amsdev1';
$DB_PASS = 'Toygoat@8';
$DB_NAME = 'tcl3ams';
$mysqli = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
$query="SELECT title, color, startsAt, endsAt, recursOn, draggable, resizable, actions from calendar";
$result = $mysqli->query($query) or die($mysqli->error.__LINE__);
$arr = array();
if($result->num_rows > 0) {
$json_response = "[";
while($row = $result->fetch_assoc()) {
$arr[] = $row;
$json_response = $json_response.'{title: "'.$row["title"].'", ';
$json_response = $json_response.'color: '.$row["color"].', ';
$json_response = $json_response.'startsAt: "'.$row["startsAt"].'", ';
$json_response = $json_response.'endsAt: "'.$row["endsAt"].'", ';
$json_response = $json_response."recursOn: '".$row["recursOn"]."', ";
$json_response = $json_response.'draggable: '.$row["draggable"].', ';
$json_response = $json_response.'resizeable: '.$row["resizable"].', ';
$json_response = $json_response.'actions: '.$row["actions"].'}, ';
}
$json_response = substr($json_response,0,strlen($json_response)-2);
$json_response = $json_response."]";
}
//header('Content-Type: application/json', true);
//header("Content-Type: application/json; charset=utf-8");
//$json_response = json_encode($arr);
echo json_encode($json_response);
/*
$ch = curl_init('/ams/index.html');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_response);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($json_response))
);
$result = curl_exec($ch);
*/
?>
angular.module('mwl.calendar.docs', ['mwl.calendar', 'ngAnimate', 'ui.bootstrap', 'colorpicker.module']);
angular
.module('mwl.calendar.docs') //you will need to declare your module with the dependencies ['mwl.calendar', 'ui.bootstrap', 'ngAnimate']
.controller('KitchenSinkCtrl', function($scope, $http, moment, alert, calendarConfig) {
var vm = this;
//These variables MUST be set as a minimum for the calendar to work
vm.calendarView = 'month';
vm.viewDate = new Date();
var actions = [{
label: '<i class=\'glyphicon glyphicon-pencil\'></i>',
onClick: function(args) {
alert.show('Edited', args.calendarEvent);
}
}, {
label: '<i class=\'glyphicon glyphicon-remove\'></i>',
onClick: function(args) {
alert.show('Deleted', args.calendarEvent);
}
}];
$http.get("ajax/getCalendarBk2.php").success(function(data){
vm.events = JSON.parse(data);
window.alert(vm.events);
});
/*
vm.events = [{title: "Testerson", color: calendarConfig.colorTypes.info, startsAt: "2016-10-10 10:00:00", endsAt: "2016-10-10 11:00:00", recursOn: '', draggable: true, resizeable: true, actions: actions}, {title: "Anoter Testerson", color: calendarConfig.colorTypes.info, startsAt: "2016-10-12 11:00:00", endsAt: "2016-10-12 12:00:00", recursOn: '', draggable: true, resizeable: true, actions: actions}, {title: "This is a really long Testerson that occurs on every year", color: calendarConfig.colorTypes.warning, startsAt: "2016-10-14 13:00:00", endsAt: "2016-10-14 14:00:00", recursOn: 'year', draggable: true, resizeable: true, actions: actions}];
*/
vm.isCellOpen = true;
vm.addEvent = function() {
vm.events.push({
title: 'New event',
startsAt: moment().startOf('day').toDate(),
endsAt: moment().endOf('day').toDate(),
color: calendarConfig.colorTypes.important,
draggable: true,
resizable: true
});
};
vm.eventClicked = function(event) {
alert.show('Clicked', event);
};
vm.eventEdited = function(event) {
alert.show('Edited', event);
};
vm.eventDeleted = function(event) {
alert.show('Deleted', event);
};
vm.eventTimesChanged = function(event) {
alert.show('Dropped or resized', event);
};
vm.toggle = function($event, field, event) {
$event.preventDefault();
$event.stopPropagation();
event[field] = !event[field];
};
});