jQuery-tokeninput失败:"term"是不确定的? [英] jQuery-tokeninput failing: "term" is undefined?

查看:112
本文介绍了jQuery-tokeninput失败:"term"是不确定的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Rails应用程序中,我尝试使用jquery-tokeninput.我一切正常-json响应和所有-但是当在tokenized字段中键入任何内容时脚本出错,抱怨:

In my rails application I am trying to use jquery-tokeninput. I have everything working - json response and all - but the script errors out when anything is typed into the tokenized field, complaining:

TypeError: term is undefined    
--> return term.replace(regexp_special_chars, '\\$&');

同时加载了jQuery和tokeninput脚本.是什么原因造成的?

Both jQuery as well as the tokeninput scripts are loaded. What could cause this?

推荐答案

听起来您可能需要指定propertyToSearch.默认情况下,Tokeninput查找一个名称"字段,但是如果您在json响应中没有该字段,则需要告诉它要查看的内容.例如,如果您的json看起来像这样:

It sounds like you might need to specify propertyToSearch. By default, Tokeninput looks for a "name" field, but if you don't have that field in the json response, you need to tell it what to be looking at. For example, if your json looks like this:

[
  {"id":"856","title":"House"},
  {"id":"1035","title":"Desperate Housewives"},
  ...
]

然后,您需要确保包含以下内容:

Then you need to make sure you include this:

$('#tvshow_tokens').tokenInput('/tvshows.json', { propertyToSearch: 'title' });

这篇关于jQuery-tokeninput失败:"term"是不确定的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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