【发布时间】:2018-05-08 11:19:40
【问题描述】:
我正在尝试从 Spring Boot 服务中获取数据,并用于填充 Typeahead。
当我开始在文本字段中输入时出现此错误
HTML
<input autocomplete="off" type="text"
ng-model="loadStopForm.stop" name="typeahead-2"
data-provide="typeahead" class="typeahead-2 form-control">
控制器代码
$.get(serviceCompanyAll, function(data) {
$('.typeahead-2').typeahead({
source: data
});
}, 'json');
数据:01,无效的数据 - 请参阅数据:02,有效。
[
{
"@type":"CR",
"companyId":1819,
"companyCode":"NVX",
"legalName":"Navex",
"dbaName":"Navex Inc.",
"formation":"P",
"firstName":null,
"middleName":null,
"lastName":null,
"dob":null,
"registeredAgent":{
"personId":2,
"category":null,
"firstName":"Arthur",
"middleName":"Parho",
"lastName":"Benjiman",
"dob":null,
"addresses":null,
"contacts":null,
"fullName":"Benjiman, Arthur"
},
"filingDate":null,
"filingNo":null,
"documentNumber":null,
"ssn":null,
"ein":null,
"internal":true,
"business":{
"code":"CR",
"value":"Carrier"
},
"locations":[
{
"id":1821,
"landmark":"4104 Banner Dr.",
"type":{
"code":"P",
"value":"Physical"
},
"street1":"4104 Banner Dr.",
"street2":null,
"city":"Houston",
"state":"TX",
"zip":"77550",
"country":null,
"latitude":null,
"longitude":null,
"contacts":[
],
"action":0
}
],
"mcNumber":"124578",
"dotunitSeries":"111",
"billingMethod":null,
"businessName":"Navex"
}, {
"@type":"SH",
"companyId":1824,
"companyCode":null,
"legalName":null,
"dbaName":null,
"formation":"I",
"firstName":"Sikandar",
"middleName":"",
"lastName":"Ali",
"dob":"05/01/2018",
"registeredAgent":null,
"filingDate":null,
"filingNo":null,
"documentNumber":null,
"ssn":124578963,
"ein":null,
"internal":true,
"business":{
"code":"SH",
"value":"Shipper"
},
"locations":[
{
"id":1825,
"landmark":"2202 Jennifer St",
"type":{
"code":"P",
"value":"Physical"
},
"street1":"2202 Jennifer St",
"street2":null,
"city":"Dallas",
"state":"TX",
"zip":"77880",
"country":null,
"latitude":null,
"longitude":null,
"contacts":[
{
"id":1826,
"medium":{
"code":"EM",
"value":"Email"
},
"serviceLocator":"sikandarali744@gmail.com",
"prefered":true,
"action":0
}
],
"action":0
}
],
"dotunitSeries":null,
"billingMethod":null,
"mcNumber":null,
"businessName":"Ali, Sikandar"
},
{
"@type":"TS",
"companyId":1827,
"companyCode":"",
"legalName":"Wayis",
"dbaName":"",
"formation":"C",
"firstName":null,
"middleName":null,
"lastName":null,
"dob":null,
"registeredAgent":null,
"filingDate":null,
"filingNo":null,
"documentNumber":null,
"ssn":null,
"ein":null,
"internal":true,
"business":{
"code":"TS",
"value":"Truck Stop"
},
"locations":[
{
"id":1828,
"landmark":"2001 Ravi St",
"type":{
"code":"P",
"value":"Physical"
},
"street1":"2001 Ravi St",
"street2":null,
"city":"Dallas",
"state":"HI",
"zip":"12345",
"country":null,
"latitude":null,
"longitude":null,
"contacts":[
],
"action":0
}
],
"dotunitSeries":null,
"billingMethod":null,
"mcNumber":null,
"businessName":"Wayis"
}, {
"@type":"BR",
"companyId":1871,
"companyCode":"",
"legalName":"E2 Financial",
"dbaName":"E2F",
"formation":"C",
"firstName":null,
"middleName":null,
"lastName":null,
"dob":null,
"registeredAgent":null,
"filingDate":null,
"filingNo":null,
"documentNumber":null,
"ssn":null,
"ein":null,
"internal":false,
"business":{
"code":"BR",
"value":"Broker"
},
"locations":null,
"mcNumber":"124578",
"billingMethod":"MCS",
"dotunitSeries":null,
"businessName":"E2 Financial"
}
]
数据:02,此数据工作正常:
[
{
"name": "Ethel Price",
"gender": "female",
"company": "Enersol"
},
{
"name": "Claudine Neal",
"gender": "female",
"company": "Sealoud"
},
{
"name": "Beryl Rice",
"gender": "female",
"company": "Velity"
},
{
"name": "Wilder Gonzales",
"gender": "male",
"company": "Geekko"
}
]
请仔细阅读:
- 在数据中:01,[姓名、性别、公司]:正在使用姓名执行搜索。
- 在数据中:02、[@type、companyId、companyCode、legalName 等....]:搜索应该通过 legalName/companyId 或任何其他字段执行,没关系。
请指导我如何执行此操作?
谢谢。
【问题讨论】:
-
你在哪里使用
b.toLowercase()?? -
@RameshRajendran 没有。
-
@RameshRajendran 如果我使用数据:02,则预输入工作正常。但不适用于数据:01
-
添加到我的答案中。请在下面查看我的注意点
-
@RameshRajendran 好的,我不想使用 legalName 进行搜索,它可以使用 companyId 吗?因为 companyId 永远不会为空。