gpt4 book ai didi

angularjs - Angular ui-calendar拖放对象

转载 作者:行者123 更新时间:2023-12-02 04:49:30 25 4
gpt4 key购买 nike

我正在尝试使用 angular-ui-calendar一起angular-dragDrop创建类似于 fullcalendar 中的示例的内容,可以将外部事件拖到日历中。
我已经检查了 How to drag&drop elements onto a calendar with angular directives only线程,但我不知道如何获取我放入 callendar 的对象并将其添加到事件数组中。
Here is my trying

  • 风景

    <div id="wrap">
    <div id="external-events">
    <h4>Draggable Events</h4>
    <label ng-repeat="item in eventList">
    <div class="fc-event" data-drag="true"
    data-jqyoui-options="{revert: 'invalid'}"
    jqyoui-draggable="{index: {{$index}},placeholder:true,animate:true}">{{item.title}}</div>
    </label>


    </div>
    <br />
    <div style="clear:both"></div>
    <div class="calendar"
    ng-model="eventSources"
    calendar="myCalendar1"
    ui-calendar="uiConfig.calendar"
    data-drop="true"
    jqyoui-droppable="{multiple:true}"></div>

    </div>


  • 控制者

    app.controller('MainCtrl', function($scope) {


    var date = new Date();
    var d = date.getDate();
    var m = date.getMonth();
    var y = date.getFullYear();


    $scope.eventList=[
    {title:'Event 1'},
    {title:'Event 2'},
    {title:'Event 3'},
    {title:'Event 4'}
    ];

    $scope.eventSources=[];

    $scope.events = [
    {title: 'All Day Event',start: new Date(y, m, 1)},
    {title: 'Birthday Party',start: new Date(y, m, d + 1, 19, 0),end: new Date(y, m, d + 1, 22, 30),allDay: false},
    {title: 'Click for Google',start: new Date(y, m, 28),end: new Date(y, m, 29),url: 'http://google.com/'}
    ];

    $scope.uiConfig = {
    calendar:{
    height: 450,
    editable: true,
    droppable: true,
    drop: function (date, allDay, jsEvent, ui) {
    console.log('Here ,but where is the object?');
    },
    header:{
    left: 'title',
    center: '',
    right: 'today prev,next'
    }
    }
    };

    $scope.eventSources = [$scope.events];

在此先感谢您的帮助

最佳答案

我知道这已经晚了 2 年,但我希望它能帮助遇到同样问题的其他人。

我遇到了同样的问题,并设法让它以与您在代码中执行的方式略有不同的方式工作。

我的 Controller :

$scope.eventSources = [{
// Each time an element is dropped in the calendar this event will fire
events (start, end, _, callback) {
start = moment().startOf('month');
end = moment().endOf('month');
// In my case I have many events I'd like to render, so I make a call to my server to get them
$http.get('/calendar_event').then(function (data) {
let events = [];
angular.forEach(data.data,function(e){
events.push({
title: 'Some Event',
start: moment(e.start_date),
end: moment(e.end_date)
});
});
// This callback calls eventRender in $scope.uiConfig
callback(events);
});
}
}];

$scope.uiConfig = {
calendar: {
// calendar configurations...
droppable: true,
drop: function(date,jsEvent,ui,resourceId){
// Here, in my case, I make a call to my server and
// store information in the database
},
eventRender: function (event, element, view) {
// This function renders the event in the calendar
let content = $('.fc-content', element).first();
content.empty();
let append = '';
let append = '';
append += '<div>';
let title = 'Some Title';
append += `<p><b>${title}</b></p>`;
append += '</div>';
// Here I make an HTML element that will be inserted in the day I dropped it at the calendar
content.append(append);
}
}
}

我的 HTML:

<div ui-calendar="uiConfig.calendar" ng-model="eventSources" class="calendar" calendar="calendar"></div>

这就是我将事件拖放到日历后设法在我的日历中呈现事件的方式。

我希望这对遇到同样问题的人有所帮助。

关于angularjs - Angular ui-calendar拖放对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30008424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com