我在我的应用程序中使用typeahead,我已将其包含在
中<link rel="stylesheet" href="https://twitter.github.io/typeahead.js/css/examples.css"/>
<script src="https://twitter.github.io/typeahead.js/releases/latest/typeahead.bundle.js"></script>
但我仍然得到typeahead不是函数错误。我甚至包括了jquery 1.10.2版本文件。以下是我的代码
<script>
var docarray=[];
var condarray=[];
var specarray=[];
$(document).ready(function() {
var doctorjsonurl = "http://xxxxxxxxxxx/doctorfeed/doctortypeahead.jsp";//just for security
$.ajax({
type :"GET",
dataType: "json",
url : "/childrensplugin/proxy.jsp?reqUrl="+encodeURIComponent(doctorjsonurl),
success : function(data){
for(i=0;i<data.doctornames.length;i++){
docarray.push(data.doctornames[i]);
}
var substringMatcher = function(strs) {
return function findMatches(q, cb) {
var matches, substringRegex;
matches = [];
substrRegex = new RegExp(q, 'i');
$.each(strs, function(i, str) {
if (substrRegex.test(str)) {
matches.push(str);
}
});
cb(matches);
};
};
$('#the-doc .typeaheaddoc').typeahead({
hint: true,
highlight: true,
minLength: 3
},
{
name: '',
source: substringMatcher(docarray)
});
},
error: function (xhr, ajaxOptions, thrownError) {
// alert(xhr.status);
// alert(thrownError);
}
});
var condjsonurl = "http://xxxxxxxx/doctorfeed/condtreatsforcondtreatsearchtypeahead.jsp";
$.ajax({
type :"GET",
dataType: "json",
url : "/childrensplugin/proxy.jsp?reqUrl="+encodeURIComponent(condjsonurl),
success : function(data){
for(i=0;i<data.allconditions.length;i++){
specarray.push(data.allconditions[i]);
}
for(i=0;i<data.alltreatments.length;i++){
specarray.push(data.alltreatments[i]);
}
var substringMatcher = function(strs) {
return function findMatches(q, cb) {
var matches, substringRegex;
matches = [];
substrRegex = new RegExp(q, 'i');
$.each(strs, function(i, str) {
if (substrRegex.test(str)) {
matches.push(str);
}
});
cb(matches);
};
};
$('#the-cond .typeaheadcond').typeahead({
hint: true,
highlight: true,
minLength: 1
},
{
name: '',
source: substringMatcher(specarray)
});
},
error: function (xhr, ajaxOptions, thrownError) {
// alert(xhr.status);
// alert(thrownError);
}
});
});
</script>
有谁能告诉我这里我缺少的东西..
答案 0 :(得分:0)