admin管理员组文章数量:1332330
In previous versions of Full Calendar, I would use eventRender to manipulate the event element and add data attributes.
Now that we are tasked with upgrading to v5, it looks like eventRender was deprecated and I cannot find a way to do the same thing.
In the docs here... I am able to use eventDidMount to access the element (el) - however any call to attr or data result in a "attr is not defined" error.
eventDidMount: function(data) {
data.el.data('res', 123);
},
data.el.data is not a function
So knowing data is jQuery, I try this...
eventDidMount: function(data) {
$(data.el).data('res', 123);
},
No errors anymore, but also no data attribute added.
So I also tried using "append" to insert an element with an attribute on it, but that adds it as plain text.
eventDidMount: function(data) {
data.el.append('<span data-id="123"></span>');
},
Driving myself mad here trying to do something relatively simple, has anyone else run into this?
In previous versions of Full Calendar, I would use eventRender to manipulate the event element and add data attributes.
Now that we are tasked with upgrading to v5, it looks like eventRender was deprecated and I cannot find a way to do the same thing.
In the docs here... https://fullcalendar.io/docs/event-render-hooks I am able to use eventDidMount to access the element (el) - however any call to attr or data result in a "attr is not defined" error.
eventDidMount: function(data) {
data.el.data('res', 123);
},
data.el.data is not a function
So knowing data is jQuery, I try this...
eventDidMount: function(data) {
$(data.el).data('res', 123);
},
No errors anymore, but also no data attribute added.
So I also tried using "append" to insert an element with an attribute on it, but that adds it as plain text.
eventDidMount: function(data) {
data.el.append('<span data-id="123"></span>');
},
Driving myself mad here trying to do something relatively simple, has anyone else run into this?
Share Improve this question asked Oct 28, 2020 at 10:51 CollinsCollins 1,15914 silver badges35 bronze badges 2-
2
“So knowing data is jQuery, I try […] No errors anymore, but also no data attribute added.” - that’s not what
.data()
does, see docs: “Using the data() method to update data does not affect attributes in the DOM. To set a data-* attribute value, use attr.” – C3roe Commented Oct 28, 2020 at 10:59 - Thank you, I think you are correct - so it was working, I just wasn't seeing it! – Collins Commented Oct 28, 2020 at 11:01
1 Answer
Reset to default 9Its always the way. I tear my hair out for 30 mins, post a question, then find an answer.
eventDidMount: function(data) {
data.el.setAttribute("data-id", 123);
},
本文标签: javascriptFull Calendar v5 Add Attribute to EventStack Overflow
版权声明:本文标题:javascript - Full Calendar v5 Add Attribute to Event - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742333396a2455144.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论