Select2 callback function when
Select2 callback function when
我们使用Select2作为标记输入。我们需要在选择标签时触发自动保存。Select2中是否有一个回调,用于选择新的或现有的标记?
$(".tagstypeahead").select2({
tags: true,
tokenSeparators: [','],
createSearchChoice: function (term) {
return {
id: $.trim(term),
text: $.trim(term) // + ' (new tag)' - Adds new tag to the end here
};
},
ajax: {
url: '/tags/typeahead.json',
dataType: 'json',
data: function(term, page) {
return {
q: term
};
},
results: function(data, page) {
return {
results: data
};
}
},
// Take default tags from the input value
initSelection: function (element, callback) {
var data = [];
function splitVal(string, separator) {
var val, i, l;
if (string === null || string.length < 1) return [];
val = string.split(separator);
for (i = 0, l = val.length; i < l; i = i + 1) val[i] = $.trim(val[i]);
return val;
}
$(splitVal(element.val(), ",")).each(function () {
data.push({
id: this,
text: this
});
});
callback(data);
}
});
我不认为select2
有更改回调,但可以使用jQuery
在该元素上绑定一个更改事件
$elem.unbind('change');
$elem.change(function (e) {
var tags = $elem.select2('data');
// code
});
相关文章:
- 直接在函数声明上使用function.prototype.bind
- jQuery:.click(function(){(element),collapse('show',f
- jQuery.when()在循环中被忽略
- 如果连接类型为none,则Javascript Function Only警报
- onLoad function phonegap android
- reducers在redux中得到Function not Object,what'it’他错了
- WIll window.addEventListener(“加载”,function(),false);等待浏览器自动填
- $(document).ready和jQuery(function($)不工作;jQuery已定义,但脚本尚未定义;t进
- 为什么$.when().pipe().then()有效,而$.when
- 为什么有些jQuery程序员使用像$.get、$.getJSON和$.when这样的jQuery函数来代替$.ajax
- Javascript onunload function
- 在init function()中调用getElementById(“..”),而不是想用它做点什么的函数
- spyOn:应为间谍,但得到了Function
- 通过$.when传播进度通知
- (typeof variable === “function”) 和 jQuery.isFunction() 有什么区别
- this内部的值返回this.each(function(){})
- Select2 callback function when
- $.when( 2 conditions ).then(function(){});
- undefined is not a function when evaluating 'this.batman
- jQuery When Done on dynamically pulled function call