【问题标题】:Getting tagLabel in jquery Tag-it在 jquery Tag-it 中获取 tagLabel
【发布时间】:2013-04-11 09:21:09
【问题描述】:

这是我的代码:

$("#AddFriendToGroup" + GroupID).tagit({
                    allowDuplicates: false,
                    readOnly: false,
                    autocomplete: { source: function (request, showChoices) {
                        $.ajax({
                            type: 'POST',
                            url: 'ChatPageTest.aspx/tagFriendAutocomplete',
                            data: "{'ClientID':'" + $("#UserID").val() + "','ClientName': '" + request.term + "'}",
                            contentType: 'application/json; charset=utf-8',
                            dataType: 'json',
                            success: function (data) {
                                returndData = data;
                                showChoices($.map(data.d, function (item) {

                                    return {
                                        label: item.split('-')[0],
                                        val: item.split('-')[1]
                                    }
                                }))
                            },
                            error: function (xhr) {
                                alert("responseText: " + xhr.responseText);
                            }
                        });
                    }
                    },
                    beforeTagAdded: function (event, ui) {

                        if ($.inArray(ui.tagLabel, returndData) == -1) return false;
                    },
                    minLength: 2
                }); // tagit

服务器端:

public static string[] tagFriendAutocomplete(int ClientID,string ClientName)
{
    List<string> Friends = new List<string>();
    string query = "select fr.FRIEND_ID,c.[USER_NAME] from clients c inner join friends fr on c.CLIENT_ID=fr.FRIEND_ID and fr.CLIENT_ID=" + ClientID + " and c.[USER_NAME] like '%" + ClientName + "%' ";

    DataTable dt = new SQLHelper(SQLHelper.ConnectionStrings.WebSiteConnectionString).getQueryResult(query);
    if (dt.Rows.Count > 0)
    { 
       for(int i=0;i<dt.Rows.Count;i++)
       {
          Friends.Add(string.Format("{0}-{1}",dt.Rows[i]["USER_NAME"], dt.Rows[i]["FRIEND_ID"]));
        }
    }

    return Friends.ToArray();
}

我的问题是当我尝试从自动完成建议中添加新标签时,不会添加新标签我想我的问题出在 beforeTagAdded 函数中,谁能帮助我

【问题讨论】:

    标签: jquery tag-it


    【解决方案1】:
    .tagit("add", {label: 'tag', value: 12})
    

    我在文档 check it out 中找到了这个

    您似乎应该为TRUE启用allowNewTags选项,这可能会导致错误,因为您尝试插入新标签而插件不允许这样做,check options too

    【讨论】:

      猜你喜欢
      • 2012-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多