urls.py
上面的bootstrap令牌字段在本地工作,但在使用远程访问时它不起作用..
答案 0 :(得分:4)
我遇到了同样的问题并得到了产品的解决方案。
我假设您应该将这些css和js文件添加到您的视图文件中
= stylesheet_link_tag 'sales_crm/tokenfield-typeahead.css'
= stylesheet_link_tag 'sales_crm/bootstrap-tokenfield.css'
%script{:src => "//code.jquery.com/ui/1.10.3/jquery-ui.js", :type => "text/javascript"}
= javascript_include_tag "sales_crm/bootstrap-tokenfield.js"
= javascript_include_tag "sales_crm/typeahead.bundle.min.js"
查看文件: 由于我使用过Haml,因此在视图文件中添加以下行,您需要在其中添加令牌字段功能
%input#tokenfield-typeahead.form-control.add_locality_data{:type => "text", :value => "", :identifier=> "Locality"}/
第1步:初始化BloodHound搜索引擎
var engine = new Bloodhound({
remote: {
url: '/sales_crm/leads/get_lead_associated_info?query=%QUERY&model_class='+$('.add_locality_data').attr("identifier"),
filter: function (response) {
var tagged_user = $('#tokenfield-typeahead').tokenfield('getTokens');
console.log(tagged_user)
return $.map(response.leads, function (user) {
console.log(user)
var exists = false;
// console.log("velava saranam");
for (i=0; i < tagged_user.length; i++) {
if (user.value == tagged_user[i].value) {
var exists = true;
}
}
if (!exists) {
return {
value: user.value,
label: user.label
};
}
});
}
},
datumTokenizer: function (d) {
return Bloodhound.tokenizers.whitespace(d.value);
},
queryTokenizer: Bloodhound.tokenizers.whitespace
});
engine.initialize();
步骤2:然后初始化令牌字段功能
$('#tokenfield-typeahead').tokenfield({
delimiter: false,
typeahead: [
{
name: 'users',
displayKey: 'label',
source: engine.ttAdapter()
}
]
})
.on('tokenfield:createtoken', function (e) {
var existingTokens = $(this).tokenfield('getTokens');
if (existingTokens.length) {
$.each(existingTokens, function(index, token) {
console.log(token)
if (token.value === e.attrs.value) {
e.preventDefault();
}else{
console.log(e.attrs.value)
}
});
}else{
console.log(e.attrs.value)
}
});