Reputation: 219
I am trying to implement search and each time getting this error... cannot read property 'addOption' on undefine in javascript selectize. I have checked that my result array have data.
My js code.
var selectSearchValue, $selectSearchValue;
var results = [];
var list_selector = $('.data-list');
list_selector.each(function (value) {
results.push({
id: $(this).attr('data-id'),
name: $(this).attr('data-name'),
code: $(this).attr('data-code'),
hall: $(this).attr('data-hall'),
location: $(this).attr('data-location')
});
});
selectSearchValue.addOption(results);
selectSearchValue.refreshOptions();
$selectSearchValue = $('#searchItems').selectize({
valueField: 'id',
labelField: 'name',
searchField: ['hall', 'name', 'code', 'location'],
render: {
option: function (item, escape) {
return '<div class="item-wrap">' +
'<span class="name">' + escape(item.hall) + '</span>' +
'<span class="code">' + escape(item.code) + '</span>' + '<div class="clearfix"></div>' +
'<span class="venue-name">' + escape(item.name) + ', </span>' +
'<span class="location">' + escape(item.location) + '</span>' +
'</div>';
}
}
});
selectSearchValue = $selectSearchValue[0].selectize;
Upvotes: 0
Views: 1281
Reputation: 15941
You're trying to add options to selectSearchValue
(line 19) before you've defined selectSearchValue
(line 42).
Upvotes: 1