0

我正在使用 Jquery tag-it 从远程 json 字符串中获取关键字列表——这很好用。

但是,我现在遇到的情况是,当您键入它试图在

somefile.php?q=foo

(foo 是您刚刚输入的内容。这将向下钻取标签列表以仅显示其中包含“foo”的那些。

我正在使用 Laravel 4,所以我需要基本上更改 ajax 请求,以便它改为/somefile/foo. 有没有办法做到这一点?我一直在疯狂地寻找,但找不到解决方案。

作为参考,这是我目前拥有的 tag-it 代码:

$("#tags").tagit({
    autocomplete: {delay: 0, minLength: 2},
    allowSpaces: true,
    onlyAvailableTags : false,
    tagSource: function(search, showChoices)
    {
        var that = this;
        $.ajax({
            url:        "/admin/keywords/autocomplete",
            data:   { term:search.term },
            dataType: "json",
            success:    function(choices)
            {
                showChoices(that._subtractArray(choices, that.assignedTags()));
            }
        });
    }
});
4

1 回答 1

0

好的,我想我已经通过反复试验自己解决了这个问题——现在可以了。

我已经调整了我的 Laravel 路由,以便以下路径将对抛出的任何内容执行 '%LIKE%' sql 查询:

http://domain.com/admin/keywords/autocomplete/search/{term}

使用这个我修改了 tagit 插件中的 ajax 调用,而不是将输入附加到 url 的末尾。最终代码如下所示:

$("#tags").tagit({
    autocomplete: {delay: 0, minLength: 2},
    allowSpaces: true,
    onlyAvailableTags : false,
    tagSource: function(search, showChoices)
    {
        var that = this;
        $.ajax({
            url:        "/admin/keywords/autocomplete/search/" + search.term,
           // data:   { term:search.term },
            dataType: "json",
            success:    function(choices)
            {
                showChoices(that._subtractArray(choices, that.assignedTags()));
            }
        });
    }
});

这似乎确实有效,而且出奇的敏捷。我知道可能有更好的方法来做到这一点,但这是我目前能做的最好的。

于 2013-05-13T14:54:37.137 回答