Tokeninput自动完成不工作的Grails [英] Tokeninput Autocomplete not working in grails

查看:177
本文介绍了Tokeninput自动完成不工作的Grails的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得这是更重要的是grails.I的jQuery的问题想使 tokeninput 有一个Grails的工作形成如下输入:

I think this is more of a jQuery question than that of grails.I am trying to make tokeninput work with a grails form with the following input:

<g:field type="text" name="tags" id="my-text-input"></g:field>

这被呈现在网页上的:

<input type="text" autocomplete="off" id="token-input-my-text-input" style="outline: none; width: 30px;">

下面是在上面的链接提到我的jQuery code:

Here is my jQuery code as mentioned in the above link:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="yourfiles/jquery.tokeninput.js"></script>
<link rel="stylesheet" type="text/css" href="yourfiles/token-input.css" />

<script type="text/javascript">
$(document).ready(function () {
    $("#my-text-input").tokenInput("/TaggableDemo/product/tags");
});
</script>

ProductController的下标签的动作是:

The tags action under ProductController is as:

def tags = {

        render Tag.findAllByTagnameIlike("${params.q}%")*.tagname as JSON
    }

标签域有3项:Tag1中,与Tag2,TAG3
当我在有关输入元素T型,标签控制器不会被调用为自动完成,而且其返回正确的JSON(我发现这个通过调试),但没有被显示在自动完成DIV弹出。我不知道什么是错在这里。因此,任何人可以帮助做工作的?

The Tag domain has 3 entries: "Tag1","Tag2","Tag3" When i type "T" in the input element in question, the tags controller does get invoked for autocomplete, and also its returning the correct json(I found this by debugging).But nothing gets displayed in the autocomplete div popup. I wonder whats wrong here. So anyone could help making it work?

推荐答案

试试这个:

def tags = {
    def foundTags = Tag.findAllByTagnameIlike("${params.q}%")
    def output = []
    foundTags.each {
        output.add([id: it.id, name: it.tagname]) // assumes Tag has an id field exposed
    }
    render output as JSON
}

code没有测试不好意思,所以可能有错误。

Code not tested sorry, so may have bugs.

这篇关于Tokeninput自动完成不工作的Grails的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆