corejavascript / corejavascript/typeahead.js

My Typeahead remote is not showing results

Open
#261 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
968
Forks
231
PR merge metrics
No merged PRs in 30d

Description

Hi there,
My typeahead remote not showing results. Can any one help?

1. Here is my Json:
`{"serials":[{"value":"CXJZ5M1"},{"value":"CXJZ5M2"},{"value":"CXJZ5M3"},{"value":"CXJZ5M4"},{"value":"CXJZ5M5"},{"value":"CXJZ5M6"},{"value":"CXJZ5M7"},{"value":"CXJZ5M8"},{"value":"CXJZ5M9"},{"value":"CXJZ510"}]}`

2. My script in the View:
```
var states1 = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
remote: {
url: "/Distribution/SearchAssetSerialsofAssetJson?id=1008",
wildcard: '%QUERY'
}
});
$('#the-basics .typeahead').typeahead(null,
{
name: 'serials',
display: 'value',
source: states1
});
```

3. Here is my Controller-Action:
```
public JsonResult SearchAssetSerialsofAssetJson(int id)
{
if (id <= 0) { return Json(new { label = "Invalid Asset" }); }

Configuration conf = _context.Configuration.FirstOrDefault();
if (conf == null)
{
return Json(new { label = "Configuration not found." });
}

if (conf.InventorySystemType == (int)InvetorySystemTypeEnum.LIFO)
{
var serials = (from s in _context.StoreAssetSerial
join st in _context.Store on s.StoreId equals st.Id
join a in _context.Assets on st.AssetId equals a.Id
where s.AssetStatusId == (int)AssetStatusEnum.InStore && st.AssetId == id //&& s.SerialNo.Contains(txtSerial)
orderby s.LabeNo descending
select new
{
value = s.SerialNo
}).Take(10);

return Json(new { serials });
}
else
{
var serials = (from s in _context.StoreAssetSerial
join st in _context.Store on s.StoreId equals st.Id
join a in _context.Assets on st.AssetId equals a.Id
where s.AssetStatusId == (int)AssetStatusEnum.InStore && st.AssetId == id //&& s.SerialNo.Contains(txtSerial)
orderby s.LabeNo ascending
select new
{
value = s.SerialNo
}).Take(10);

return Json(new { serials });
}
}
```
**Another thing:** How can I pass parameter in the remote: url: (say like, url: `"/Distribution/SearchAssetSerialsofAssetJson?id=" + $(#txtAssetId).text()`)

Thanks in Advance
Tarique Iqbal

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.