在jQuery令牌输入中创建令牌 [英] create tokens in jquery token input

查看:90
本文介绍了在jQuery令牌输入中创建令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我的jquery令牌输入工作正常.

Presently my jquery token input is working perfectly fine.

我无法创建令牌,该令牌不在列表中

Am not able to create token, which is not in the list

我在此处看到,该功能已实现.但是,没有关于我该如何使用它的文档.

I have seen here, that this functionality is implemented. But there is no documentation on how we i can use this.

有人可以帮助我提供文档或演示

Can any one help me with documentation or demo

js_js.js

    $(document).ready(function () {
        $("#job_skills").tokenInput("/jobs/search_job_skills", {
            theme: "facebook",
            preventDuplicates: true,
            hintText: 'Add skills need for job',
            searchingText: 'searching skills...',
            allowCreation: true,
            creationText: 'Add new element'
        });

    });

cons_controller.rb

cons_controller.rb

  def search_job_skills
    search_for_json(Skill)
  end

  def search_for_json(model_search)
    @hash = []

    @search_res = model_search.where(['name LIKE ?', "#{params[:term]}%"])

    @search_res.each do |tag|
      @hash << { id: tag.id,
                 name: tag.name}
    end
    render json: @hash
  end

推荐答案

启动时包含allowFreeTagging: true.

不幸的是,文档几年没有更新.

Unfortunately, the documentation hasn't been updated in a few years.

还请注意,如果将allowFreeTagging设置为true,则需要将tokenValue更改为"name",因为在服务器上保存标签时,您可能希望保存名称而不是ID.

Also note that if you set allowFreeTagging to true, you will want to change the tokenValue to "name", because when you save the tag on your server, you probably want to save the name, not the id.

这里是我的代币选项

tokenOptions = {
    allowFreeTagging: true,
    tokenValue: 'name'
}

$('input#tag-input').tokenInput('/tags.json', tokenOptions);

这样,当用户选择标签时,名称将发送到服务器,并且如果有任何新的标签名称,我只需在服务器端创建它们.

This way, when a user selects tags, the names are sent to the server, and if there are any new tag names, I simply create them server-side.

这篇关于在jQuery令牌输入中创建令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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