jQuery-tokeninput failing: “term” is undefined?

╄→гoц情女王★ 提交于 2019-12-07 12:06:59

问题


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, '\\$&');

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


回答1:


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' });


来源:https://stackoverflow.com/questions/12045622/jquery-tokeninput-failing-term-is-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!