我有一个初始化函数,我想检测何时为下拉菜单删除标签(来自Semantic UI):
call.js
Template.calledit.onRendered(function() {
$('.ui.dropdown').dropdown({
onLabelRemove(value) {
console.log(value);
console.log(this._id);
}
});
});
call.html
<template name="calledit">
<div class="field">
<label>Assign Units</label>
<div id="edit_call_assign_units_{{_id}}" class="ui multiple search selection dropdown">
<input type="hidden" name="edit_call_assign_units_{{_id}}" value="{{units}}">
<i class="dropdown icon"></i>
<div class="default text">Assign Units</div>
<div class="menu">
<div class="item" data-value="420">420</div>
<div class="item" data-value="F-117">F-117</div>
<div class="item" data-value="805">805</div>
<div class="item" data-value="230">230</div>
<div class="item" data-value="506">506</div>
</div>
</div>
</div>
<template>
但是,我在检测调用它的模板的_id
时遇到问题。如何在onRendered函数中访问this._id
?
答案 0 :(得分:0)
看起来错误的背景,也许这个
Template.calledit.onRendered(function() {
var tmpl = this;
$('.ui.dropdown').dropdown({
onLabelRemove(value) {
console.log(value);
console.log(tmpl._id);
}
});
});
或者如果你使用ecmascript,那么
Template.calledit.onRendered(function() {
$('.ui.dropdown').dropdown({
onLabelRemove: (value) => {
console.log(value);
console.log(this._id);
}
});
});