jquery 自动完成:适用于第一个值,如何为下一个值启用它?

发布于 2024-10-08 17:27:57 字数 1031 浏览 0 评论 0原文

我正在使用自动完成功能,因此用户可以轻松地在输入中输入数据,如下所示:

 <?
$a = new etiqueta(0, '');
$b = $a->autocomplete_etiquetas();
?>
<script type="text/javascript">
    function cargar_autocomplete_etiquetas(){
        $("#tags").autocomplete({
            source: [<? echo $b; ?>]
        });
    }
</script>

$a = $b 它是一个 array ,结果如下:'help','please ',我','需要','能够','选择下一个项目','自动完成';

我检查了 ui 文档,但它不符合我的源方法..有什么想法吗? 我正在尝试这样(用 Bugai13 aportation 编辑):

 <?
$a = new etiqueta(0, '');
$b = $a->autocomplete_etiquetas();
?>
<script type="text/javascript">
    function cargar_autocomplete_etiquetas(){
    $("#tags").autocomplete({
        source: [<? echo $b; ?>],
        multiple: true,
        multipleSeparator: ", ",
        matchContains: true
    });
}

</script>

但我不知道该怎么做..有什么想法吗? .push 和 .pop 函数来自自动完成功能吗?或者我应该定义他们?

再次感谢!

PS:我对这个网站越来越上瘾了! PS:来吧伙计们,我认为答案对很多人来说都是非常有用的 PS:可以提供paypal奖励吗?

I'm using autocomplete so user can easly enter data on inputs, like this:

 <?
$a = new etiqueta(0, '');
$b = $a->autocomplete_etiquetas();
?>
<script type="text/javascript">
    function cargar_autocomplete_etiquetas(){
        $("#tags").autocomplete({
            source: [<? echo $b; ?>]
        });
    }
</script>

$a = $b its an array with a result like: 'help','please',i','need','to,'be able to', 'select next item',' with autocomplete';

and i checked the ui documentation, but it doesn't fith with my source method.. any idea?
I'm trying like this (edited with Bugai13 aportation):

 <?
$a = new etiqueta(0, '');
$b = $a->autocomplete_etiquetas();
?>
<script type="text/javascript">
    function cargar_autocomplete_etiquetas(){
    $("#tags").autocomplete({
        source: [<? echo $b; ?>],
        multiple: true,
        multipleSeparator: ", ",
        matchContains: true
    });
}

</script>

but i don't know how to do it.. any idea? are .push and .pop functions from the autocomplete? or shall i define, them?

thanks again!

PS: i'm getting adicted to this site!
PS: come on dudes, i think the answer will be very usefull for many people
PS: is it allowed to offer paypal reward?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

长安忆 2024-10-15 17:27:57

我使用以下方法来为带有“,”分隔符的标签进行多个自动完成工作,希望这对您有帮助:

我的代码完全可以工作。在我的例子中,在解析函数项中它只是 json 数组,尝试添加解析方法:

   $("#txtTags").autocomplete(UrlFactory.TAGS_AUTOCOMPLETE_URL, {
    matchContains: true,
    width: 320,
    max: 10,
    highlight: false,
    multiple: true,
    multipleSeparator: ", ",
    scroll: true,
    scrollHeight: 300,
    dataType: "json",
    parse: function (data) {
        var result = Result.fromJson(data);

        var items = result.getJson("Tags");
        var arr;
        if (items != null)
            arr = items.split(",");
        return $.map(arr, function (row, i) {
            return {
                data: row,
                value: row,
                result: row
            }
        });
    },
    onItemSelect: function () {

    },
    formatItem: function (data, i, n, value) {
        if (value != null) {
            value = ltrim(value);
            value = rtrim(value);
        }
        return value;
    }
});

所以,你需要这样的东西:

function cargar_autocomplete_etiquetas(){
    $("#tags").autocomplete({
        source: [<? echo $b; ?>],
        multiple: true,
        multipleSeparator: ", ",
        matchContains: true
    });
}

I've use following to get work multiple autocomplete for tags with ',' separator, hope this help your:

It's full my code that work. In my case in parse function items it just json array, try to add parse method:

   $("#txtTags").autocomplete(UrlFactory.TAGS_AUTOCOMPLETE_URL, {
    matchContains: true,
    width: 320,
    max: 10,
    highlight: false,
    multiple: true,
    multipleSeparator: ", ",
    scroll: true,
    scrollHeight: 300,
    dataType: "json",
    parse: function (data) {
        var result = Result.fromJson(data);

        var items = result.getJson("Tags");
        var arr;
        if (items != null)
            arr = items.split(",");
        return $.map(arr, function (row, i) {
            return {
                data: row,
                value: row,
                result: row
            }
        });
    },
    onItemSelect: function () {

    },
    formatItem: function (data, i, n, value) {
        if (value != null) {
            value = ltrim(value);
            value = rtrim(value);
        }
        return value;
    }
});

So, you need something like this:

function cargar_autocomplete_etiquetas(){
    $("#tags").autocomplete({
        source: [<? echo $b; ?>],
        multiple: true,
        multipleSeparator: ", ",
        matchContains: true
    });
}
似狗非友 2024-10-15 17:27:57

echo $b; 打印什么?我希望您需要类似 echo implode(',', $b) 的东西,甚至是 echo '"' . implode('", "', $b) . '" '; 为了使这个工作正常,如果 $b 确实是一个 PHP 数组。

编辑:(当然,我只是假设您使用的是 PHP,但如果它 像 PHP 并且 $ 像 PHP...)

What does echo $b; print? I would expect you would need something like echo implode(',', $b), or even echo '"' . implode('", "', $b) . '"'; to make this work, if $b really is a PHP array.

Edit: (of course I'm only assuming you're using PHP, but if it <?s like PHP and $s like PHP...)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文