【问题标题】:Ajax AutoComplete Feature with Prototype and Django带有原型和 Django 的 Ajax 自动完成功能
【发布时间】:2011-09-29 04:09:24
【问题描述】:

我想集成 Django 和 JavaScript 原型库来为表单创建自动完成功能。任何人都可以推荐一个已经用 Django 尝试过的原型功能吗?有this codealso this,我想知道是否有人会推荐其中一个用于Django。谢谢!

【问题讨论】:

    标签: python ajax django autocomplete prototypejs


    【解决方案1】:

    我从site 下载了代码 并按照那里的指示进行操作,这很简单。只需包含prototype.js、scriptaculous.js 和AutoComplete.js 文件。然后从说明中复制粘贴,并将网址从assets/ac.php?m=text&s= 更改为?m=text&s=,如果您只需要一个查询参数,甚至只需?s=

        <input type="text" id="my_ac3" name="my_ac" size="45" autocomplete="off"/> 
        <script type="text/javascript"> 
        new AutoComplete('my_ac3', '?s=', { delay: 0.25, resultFormat: AutoComplete.Options.RESULT_FORMAT_TEXT }); 
        </script>
    

    在服务器端,在该页面的视图函数中,使用以下命令启动函数:

        if request.is_ajax():
            #match the users input here, perhaps using data from your database and/or regular expressions
            text = #response text to return, in my case since I chose Options.RESULT_FORMAT_TEXT as my resultFormat, it's a string where each autocomplete item is separated by '\n'
            return HttpResponse(text, mimetype='text/plain')  # mimetype is text here in my case
    

    然后将视图函数的其余部分放在 else 子句下。

    【讨论】:

      猜你喜欢
      • 2014-06-14
      • 1970-01-01
      • 2014-09-15
      • 2013-09-27
      • 2012-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多