2

我正在使用 Soulmate https://github.com/seatgeek/soulmate在我的项目上创建一个自动完成表单,并使用本教程作为指导。http://patshaughnessy.net/2011/11/23/finding-your-soulmate-autocomplete-with-redis-in-rails-3-1

我的问题是,我如何包含该项目的网址。例如,我正在为艺术家编制索引,我希望 json 对象包含数据、指向 /artist/1 的 url

我需要这个,以便我的 jQuery 自动完成可以链接到搜索结果。

谢谢,

4

1 回答 1

1

After going to the link you provided, I see in the docs that they have a rendering callback function, presumably meant to make use of your ajax responses.

Notice how I simply returned what I wanted the list item to contain. This may not be completely accurate, but you get the idea. look in the docs further for more information. (there doesn't seem to be a lot of documentation written, though.)

var render = function(term, data, type){
    var link = "<a href="data.url.or.something">"+term+"</a>";
    return link;
}

$('#search-input').soulmate({
  renderCallback: render, //this is a reference to the function above.
  url:            'http://soulmate.YOUR-DOMAIN.com/search',
  types:          ['type1', 'type2', 'type3', 'type4'],
  selectCallback: select,
  minQueryLength: 2,
  maxResults:     5
});
于 2013-02-28T03:06:36.643 回答