【发布时间】:2016-10-04 13:54:56
【问题描述】:
我在布局中使用 Template.contentBlock 并尝试调用 Fullcalendar onRendered。
布局
<template name="layout">
{{#if appReady}}
<div class="container-fluid">
{{>header}}
{{>errors}}
<div class="row">
<div class="col-md-2">
{{> sidebar}}
</div>
<div class="col-md-10">
{{> Template.contentBlock}}
</div>
</div>
</div>
{{else}}
{{>loading}}
{{/if}}
模板
Template.userAppointments.onRendered(function() {
console.log('userAppointments rendered')
$('#calendar').fullCalendar();
$('.row').css("background-color","blue");
});
Console.log 正在显示,但 fullCalendar 引用或更改行均未显示。这让我觉得 jquery 在 Template.contentBlock 中不知何故。
提前感谢您的启发。
【问题讨论】:
-
console.log($)打印的是什么? -
@4castle ( selector, context ) { // 70 // jQuery 对象实际上只是 init 构造函数 'enhanced' ...
-
要引用模板的 jQuery 对象,您需要显式使用
this.$。所以这部分代码应该可以工作。在你的onRendered函数中放置一个断点并尝试查看$('.row')和$('#calendar')返回什么。很确定他们不在那里(也许是因为appReady是假的?)。
标签: jquery meteor fullcalendar