How to Customize Data FullcalendarBundle from a SUBMIT form

后端 未结 2 1292
旧时难觅i
旧时难觅i 2021-01-21 07:01

i have added a select form above the FullCalendar to select an user and show his events

the question is how to load the events of the user selected in the calendar

2条回答
  •  执笔经年
    2021-01-21 07:21

    The problem is a simple one - JavaScript property names are case-sensitive.

    Therefore, event.USER will not match the User property in your data.

    Change event.USER to event.User and it will work.

    Simple demo:

    var events = [{
      title: 'Event1',
      start: '2019-03-01',
      end: '2019-03-02',
      User: 'User1'
    }, {
      title: 'Event2',
      start: '2019-03-01',
      end: '2019-03-02',
      User: 'User2'
    }];
    
    events.forEach(eventRender);
    
    function eventRender(event) {
      console.log ("Testing: " + JSON.stringify(event));
      console.log("Bad code: " + (['', event.USER].indexOf("User1") >= 0));
      console.log("Good code: " + (['', event.User].indexOf("User1") >= 0));
    }

    And here's a demo of the code in action within fullCalendar: http://jsfiddle.net/mw7okq9v/


    One further point: Although your provided JSON data sample includes the User property, it's unclear whether this accurately reflects the current state of what your code is actually outputting.

    In your Event class, you have specified this property as "protected". i.e.

    protected $User;
    

    This will prevent the property being included when the object is serialised to JSON. I think you will need to make it public:

    public $User;
    

    so that the server will output this property as part of the event JSON.

提交回复
热议问题