这是我的控制器响应:
format.json { render json: @users.to_json(:methods => [:tokens, :value], :include => { :preferences => { :only => [:name] }}) }
这是解析结果的咖啡脚本:
$ ->
$('.global-search').typeahead([{
name: 'users',
remote: {
url: '/users.json?search=%QUERY'
},
header: [].join(''),
template: [
'<i class="icon icon-user icon-2x pull-left"></i>',
'<div>',
'<p>{{id}}</p>',
'<p class="descriptor">{{email}}</p>',
'<p class="descriptor">{{preferences}}{{name}}</p>',
'</div>'
].join(''),
engine: Hogan
我无法提取 :include "preferences" 名称值。不太清楚如何引用它。有任何想法吗?
谢谢,