twitter-bootstrap Typeahead TypeError: it.toLowerCase 不是函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/38320293/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Typeahead TypeError: it.toLowerCase is not a function
提问by YVS1102
Good day. Please take a look at my scrit first.
再会。请先看看我的剧本。
My JS
我的JS
$(document).ready(function(){
$("#outlet").typeahead({
source: function(query, process) {
$.ajax({
url: '<?=base_url();?>graph/outletlists',
data: {outlets:$("#outlet").val()},
type: 'POST',
dataType: 'JSON',
success: function(data) {
process(data);
console.log(data);
}
});
},
minLength: 2
});
});
My Controller
我的控制器
function outletlists()
{
extract(populateform());
$hasil = $this->modelmodel->showdata("SELECT Outlet from transaksi where outlet like '%".$outlets."%' group by Outlet");
echo json_encode($hasil);
}
and my form
还有我的表格
<div class="form-group">
<label class="col-sm-3 control-label">Outlet</label>
<div class="col-sm-5">
<input type="search" id="outlet" class="form-control" placeholder="Search..." data-provide="typeahead" />
</div>
</div>
so, I'm using Bootstrap3-typeahead. From my script above i got this error
所以,我正在使用Bootstrap3-typeahead。从我上面的脚本我得到了这个错误
from console.log(data)i already have my desired result. So my problems are i can't see any suggestion and then i got this error from firebug
从console.log(data)我已经有了我想要的结果。所以我的问题是我看不到任何建议然后我收到了这个错误firebug
return ~it.toLowerCase().indexOf(this.query.toLowerCase());
This is what i got when i input AR
这是我输入时得到的 AR
[{"Outlet":"K-AR3"},{"Outlet":"K-AR4"},{"Outlet":"K-ARN2"},{"Outlet":"K-ARN3"}]
any help would be appreciated, sorry for my bad english.
任何帮助将不胜感激,抱歉我的英语不好。
I try it to make it like the example at http://twitter.github.io/typeahead.js/examples/
我试着让它像http://twitter.github.io/typeahead.js/examples/ 上的例子
var states = ['Alabama', 'Alaska', 'Arizona', 'Arkansas', 'California',
'Colorado', 'Connecticut', 'Delaware', 'Florida', 'Georgia', 'Hawaii',
'Idaho', 'Illinois', 'Indiana', 'Iowa', 'Kansas', 'Kentucky', 'Louisiana',
'Maine', 'Maryland', 'Massachusetts', 'Michigan', 'Minnesota',
'Mississippi', 'Missouri', 'Montana', 'Nebraska', 'Nevada', 'New Hampshire',
'New Jersey', 'New Mexico', 'New York', 'North Carolina', 'North Dakota',
'Ohio', 'Oklahoma', 'Oregon', 'Pennsylvania', 'Rhode Island',
'South Carolina', 'South Dakota', 'Tennessee', 'Texas', 'Utah', 'Vermont',
'Virginia', 'Washington', 'West Virginia', 'Wisconsin', 'Wyoming'
];
$(document).ready(function() {
$("#outlet").typeahead({
autoSelect: true,
minLength: 2,
delay: 400,
source: states
});
});
and it works .
它有效。
Results from firebug
由于。。。导致的结果 firebug
POST http://localhost:84/new_store/graph/outletlists200 OK 375ms
jquery-....min.js (line 4) HeadersPostResponseHTMLCookies[{"Outlet":"K-AR3"},{"Outlet":"K-AR4"},{"Outlet":"K-ARN2"},{"Outlet":"K-ARN3"}]
TypeError: b.toLowerCase is not a function
...on(a){var b=this.displayText(a);return~b.toLowerCase().indexOf(this.query.toLowe...
bootstr....min.js (line 1, col 2903
POST http://localhost:84/new_store/graph/outletlists200 OK 375ms
jquery-....min.js (line 4) HeadersPostResponseHTMLCookies[{"Outlet":"K-AR3"},{"Outlet":"K-AR4"},{"Outlet":"K-ARN2"},{"Outlet":"K-ARN3"}]
类型错误:b.toLowerCase 不是函数
...on(a){var b=this.displayText(a);return~b.toLowerCase().indexOf(this.query.toLowe...
bootstr....min.js(第 1 行,第 2903 行
I try to change my bootstrap3-typeahead.jsto bootstrap3-typeahead.min.jsend my error become like this
我试图改变我bootstrap3-typeahead.js的bootstrap3-typeahead.min.js结束我的错误变成这样
TypeError: b.toLowerCase is not a function ...on(a){var b=this.displayText(a);return~b.toLowerCase().indexOf(this.query.toLowe...
类型错误:b.toLowerCase 不是函数...on(a){var b=this.displayText(a);return~b.toLowerCase().indexOf(this.query.toLowe...
采纳答案by Boby
as what i can see from your console.log(). you get this.
正如我从你的console.log(). 你明白了。
[{"Outlet":"K-AR3"},{"Outlet":"K-AR4"},{"Outlet":"K-ARN2"},{"Outlet":"K-ARN3"}]
you only need
你只需要
[{"K-AR3"},{"K-AR4"},{"K-ARN2"},{"K-ARN3"}]
so try to change your controller to
所以尝试将您的控制器更改为
function outletlists()
{
extract(populateform());
$hasil = $this->modelmodel->showdata("SELECT Outlet from transaksi where outlet like '%".$outlets."%' group by Outlet");
$data = array();
foreach ($hasil as $hsl)
{
$data[] = $hsl->Outlet;
}
echo json_encode($data);
}
回答by JaneH
Even though there's been an accepted answer I'm going to offer another answer, as this one did not apply to my situation. It turned out that one of my array elements was a null value. So I rewrote my data query to filter out nulls.
即使有一个公认的答案,我还是要提供另一个答案,因为这个答案不适用于我的情况。结果证明我的数组元素之一是空值。所以我重写了我的数据查询来过滤掉空值。
回答by cpoDesign
try to use following example as static code and then make it dynamic Example: http://twitter.github.io/typeahead.js/examples/.
尝试使用以下示例作为静态代码,然后使其成为动态示例:http: //twitter.github.io/typeahead.js/examples/。

