我正在使用typeahead v0.11.1顯示結果,但它沒有顯示以相同結果開始的結果。Bootstrap Typeahead沒有顯示具有valueKey以相同的值開頭的提示
我從數據庫中獲取的結果是這樣的:
Object {
Id: 4,
Title: "project manager",
Description: "project manager",
CompanyId: 1
}
Object {
Id: 6,
Title: "Software Developer",
Description: "Software Developer",
CompanyId: 1
}
Object {
Id: 7,
Title: ".NET Developer",
Description: ".NET Developer",
CompanyId: 1
}
Object {
Id: 10,
Title: "Android Developer",
Description: "Android Developer",
CompanyId: 1
}
Object {
Id: 11,
Title: "iOS Developer",
Description: "iOS Developer",
CompanyId: 1
}
Object {
Id: 13,
Title: "Sr. Android Developer",
Description: "Sr. Android Developer",
CompanyId: 1
}
Object {
Id: 14,
Title: "Sr. iOS Developer",
Description: "Sr. iOS Developer",
CompanyId: 1
}
的問題是預輸入顯示的是除了Sr. Android Developer
和Sr. iOS Developer
var position = new Bloodhound({
datumTokenizer: function (datum) {
return Bloodhound.tokenizers.whitespace(datum.Title);
},
queryTokenizer: Bloodhound.tokenizers.whitespace,
//prefetch: '../data/films/post_1960.json',
remote: {
url: '/Search/Positions?query=%QUERY',
wildcard: '%QUERY',
filter:function (positionList) {
// Map the remote source JSON array to a JavaScript object array
return $.map(positionList, function (position) {
console.log("position is:", position);
return {
Title: position.Title
};
});
}
}
});
var promisepos=position.initialize();
promisepos.done(function(){});
$('#Position').typeahead({
minLength:1,
highlight:true,
hint:false
},{
name: 'positionList',
displayKey:'Title',
source:position.ttAdapter(),
templates:{
footer: "<div class='position-wrapper'><a class='ad-ps'><i class='fa fa-user-secret'></i> Add New Position</a></div>",
notFound: function(){
var ps=$('#Position').val();
$('#PositionId').val("");
return "<div class='position-wrapper'><p>No Position found.</p><a class='ad-ps'><i class='fa fa-user-secret'></i> Add New Position</a></div>";
},
suggestion: Handlebars.compile('<div class="position-wrapper">'+
'<div class="poosition-info-wrapper">'+
'<span>{{Title}}</span>'+
'</div>'+
'</div>')
}
});
內的
filter
通過我只是複製你的代碼,並做了少量修改(使用而不是從URL抓取靜態JSON )。它沒有任何問題。我可以看到「Sr. XXX」條目。我唯一的修正是使用JSON對象結構。你能檢查你是否從服務器接收到所有有效的JSON條目嗎? – CuriousMind所以,這個URL實際上是返回JSON,而我正在接收上面提到的確切的JSON條目。 –
您可以添加瀏覽器開發工具的快照,顯示JSON嗎? – CuriousMind