Reputation: 2642
With reference to this issue, here what I did in render()
of my backbone project :
var topDepartment = serializeObjToJSON(nav.getTopDepartment(15));
//here is the result of topDepartment : [{"DepartmentName":"Test1","ID":56},{"Test2":"Professional Video Broadcast","ID":57},......]
function format(dep) { return dep.DepartmentName; };
$("#selCate").select2({
dropdownCssClass : 'bigdrop',
minimumResultsForSearch : -1,
data:{results : topDepartment,text:'DepartmentName'},
formatSelection: format,
formatResult: format});
Here the html :
<select id="selCate"></select>
Running on chrome,there's no error showed even the select
is empty. But in firefox Error: Option 'data' is not allowed for Select2 when attached to a <select> element.
occured.
Problem : There's no any option
in <select>
when I run the page.
Any idea what could be causing this. Thanks.
Upvotes: 0
Views: 523
Reputation: 2642
I solved my problem by doing this :
$("#selCate").select2({placeholder: "Select a State",dropdownCssClass : 'bigdrop', minimumResultsForSearch : -1});
_.each(nav.getTopDepartment(15),function(cat){
$('#selCate').append('<option value="' + cat.ID + '">'+ cat.DepartmentName +'</option>');
});
And this is html :
<select id="selCate">
<option></option>
</select>
Upvotes: 1