作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要从 tagit 获取值,我该怎么做?在 afterTagAdded 中,我调用 Controller 并将对象保存在 List<> 中,但我不知道如何获取该值。我需要在这里发送 -->data:{user:here the id}, the value(id), 我该怎么做?
$('#userNameFriend').tagit({
fieldName: "tags[]",
removeConfirmation: true,
singleField: true,
allowSpaces: true,
placeholderText: 'Name',
tagSource: function ajaxCall(request, response) {
$.ajax({
url: "${pageContext.request.contextPath}/getUserFriends.html",
data: {
term : request.term
},
dataType: "json",
success: function(data) {
response($.map(data.results.list, function(item) {
return{
label:" "+ item.name +" "+item.surname,
value:item.id
};
}));
}
//error: function(error){
//alert("El valor no existe");
//}
});
},
afterTagAdded: function addUser (event,ui){
//Ejecutar llamada al controller para rellenar array con los usuarios elegidos.
//alert("HOLA"+ui.tag.value);
$.ajax({
url:"${pageContext.request.contextPath}/message/fillin.html",
data:{user:here the id},
dataType: "json",
success: function(){
alert("success");
//Append al div de viajes
},
error: function(){
alert("failure"+data);
}
});
}//Adduser
})
最佳答案
如果想在afterTagAdded函数中获取标签。您只需要访问 ui 对象的属性 tagLabel,如下所示:ui.tagLabel
。
如果你想获取到目前为止已添加的所有标签。您只需通过输入中的 tagit 对象调用函数 allocateTags,如下所示: $('#userNameFriend').tagit('assignedTags')
;这将返回一个包含标签值的数组。
关于jquery - TagIt 获取值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24224182/
我是一名优秀的程序员,十分优秀!