jquery - TagIt 获取值(value)

标签 jquery

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

相关文章:

jquery - 下拉菜单中的类别子类别

javascript - Chrome 扩展解析 RSS

javascript - DataTables按属性而不是数组索引过滤对象数组

javascript - Tweet 按钮看起来像一个普通的 <a> 链接,没有任何 JS 或 CSS

javascript - 清除日期时间选择器字段中的值

javascript - jquery 向上/向下滚动按钮不起作用

Javascript MVC + 使用 jQuery 监听和调度事件

javascript - 如何将嵌套函数公开?

jquery 多个元素悬停时淡入淡出

javascript - 使用 jQuery 将 toggleClass 添加到复选框