点击按钮调用Jade mixin功能
Call Jade mixin function on button click
我正在尝试创建一个动态表,用户可以在其中按下按钮并更新表的内容。
代码
extends layout
// Builds a row in the table
mixin tableRowBuilder(modules)
tr
for module, index in modules
td
if module.name
+cardBuilder(module.name, module.time, module.location)
// Builds card to be displayed in the table
mixin cardBuilder(name, time, location)
.card-panel.teal
span.white-text
h5= name
i.material-icons.left alarm
p= time
i.material-icons.left place
p= location
block content
table#timetable
thead
tr
// Table headers here...
tbody
+tableRowBuilder(morningModules)
+tableRowBuilder(afternoonModules)
script.
function semesterOneButtonClicked() {
$('#timetable').empty();
$('#timetable').addRow(tableRowBuilder(morningModules))
$('#timetable').addRow(tableRowBuilder(afternoonModules))
}
然而,目前我得到的错误:
ReferenceError: Can't find variable: tableRowBuilder
我假设这是因为mixin
与script
不在同一上下文中。
所以我的问题是:我努力实现的目标可能吗?
在我看来,它不应该工作,因为js执行和jade执行是不同的阶段和不同的范围,你需要在jade中调用它mixin,将结果保留在一个隐藏元素中,稍后从js 获取
尝试:
extends layout
// Builds a row in the table
mixin tableRowBuilder(modules)
tr
for module, index in modules
td
if module.name
+cardBuilder(module.name, module.time, module.location)
// Builds card to be displayed in the table
mixin cardBuilder(name, time, location)
.card-panel.teal
span.white-text
h5= name
i.material-icons.left alarm
p= time
i.material-icons.left place
p= location
block content
#morning-modules-row(style='display:none')
+tableRowBuilder(morningModules)
#afternoon-modules-row(style='display:none')
+tableRowBuilder(afternoonModules)
table#timetable
thead
tr
// Table headers here...
tbody
+tableRowBuilder(morningModules)
+tableRowBuilder(afternoonModules)
script.
function semesterOneButtonClicked() {
$('#timetable').empty();
$('#timetable').addRow($('#morning-modules-row')[0].innerHTML);
$('#timetable').addRow($('#afternoon-modules-row')[0].innerHTML);
}
相关文章:
- 添加文字和评论功能更新Div
- JavaScript打印功能使日历停止工作
- 每当您在选择器内移动鼠标时,悬停功能就会重复
- 如何防止网页加载后自动启动功能
- 除修剪外的其他功能
- 悬停功能触发器
- 使用angularjs向浏览器发送servlet响应(下载功能)
- 删除CKEditor工具栏按钮,但不删除功能
- 异步facebook功能
- 如何将chrome扩展功能移植到移动设备(特别是jquery和trello)
- jQuery滚动功能只工作一次
- Graphiti中是否有任何工具提示功能
- React redux初始化功能,无论状态变化如何
- 在哪里可以学习ECMAScript标准中尚未包含的JavaScript功能
- 正在获取select上的功能id
- Rhino打印功能
- 使用(navigator.geolocation)检测浏览器功能错误
- 主体单击删除功能上的输入框宽度
- JQuery使用相同的功能自动完成各种输入文本
- 点击按钮调用Jade mixin功能