Is there is a way for me to access the updater function from outside of the typeahead scope ?
是否有一种方法可以让我从typeahead范围之外访问updater函数?
My current example is that in the updater function, I have some custom logic that creates some html and appends it to the body such as with the following snippet example:
我现在的例子是,在updater函数中,我有一些自定义逻辑,创建一些html并将其添加到正文,例如下面的代码片段示例:
updater: function(item){
$input = $('<span/>',{
class:'label label-info',
text:item,
style:'margin-left:4px'
});
...
$('#tagContainer').append($input);
}
Now my question is: Is it possible for me to link this function to a button so that it is triggered when the button is clicked, considering that I will pass it the 'item' parameter ?
现在我的问题是:我是否可以将这个函数链接到一个按钮上,这样当按钮被单击时它就会被触发,考虑到我将把它传递给它的“item”参数?
I guess this problem involves something about functions scope, and this is where my knowledge lack, and need some insight.
我想这个问题涉及到功能范围,这是我的知识缺乏的地方,需要一些洞察力。
1 个解决方案
#1
2
Define it as a separate function:
将其定义为一个单独的函数:
function appendInput(item) {
//same contents
}
update: appendInput ...
$("button").on('click', function () { appendInput(this); });
#1
2
Define it as a separate function:
将其定义为一个单独的函数:
function appendInput(item) {
//same contents
}
update: appendInput ...
$("button").on('click', function () { appendInput(this); });