TagIt获得价值

nol*_*ole 2 jquery

我需要从tagit获取值,我该怎么做?在afterTagAdded中,我调用我的控制器并将对象保存在List <>中,但我不知道如何获得该值.我需要发送到这里 - >数据:{user:here id},值(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

})
Run Code Online (Sandbox Code Playgroud)

小智 11

如果要在afterTagAdded函数中获取标记.您只需要访问ui对象的属性tagLabel,如下所示:ui.tagLabel.

如果您想获取到目前为止已添加的所有标记.你只需要调用通过TAG-IT对象的函数assignedTags在你的输入,如:$('#userNameFriend').tagit('assignedTags'); 这将返回一个带有标签值的数组.