gpt4 book ai didi

jquery - TagIt 获取值(value)

转载 作者:行者123 更新时间:2023-12-01 02:02:31 25 4
gpt4 key购买 nike

我需要从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com