Add some safety when rendering a dropdown button to make sure it has

content.
This commit is contained in:
Robin Ward 2015-01-15 15:43:20 -05:00
parent 4a11bb5227
commit e4e239c159
1 changed files with 16 additions and 13 deletions

View File

@ -31,20 +31,23 @@ export default Discourse.View.extend(StringBuffer, {
buffer.push("</button>"); buffer.push("</button>");
buffer.push("<ul class='dropdown-menu'>"); buffer.push("<ul class='dropdown-menu'>");
var self = this; var contents = this.get('dropDownContent');
this.get('dropDownContent').forEach(function(row) { if (contents) {
var id = row.id, var self = this;
title = row.title, contents.forEach(function(row) {
iconClass = row.styleClasses, var id = row.id,
description = row.description, title = row.title,
className = (self.get('activeItem') === id ? 'disabled': ''); iconClass = row.styleClasses,
description = row.description,
className = (self.get('activeItem') === id ? 'disabled': '');
buffer.push("<li data-id=\"" + id + "\" class=\"" + className + "\"><a href>"); buffer.push("<li data-id=\"" + id + "\" class=\"" + className + "\"><a href>");
buffer.push("<span class='icon " + iconClass + "'></span>"); buffer.push("<span class='icon " + iconClass + "'></span>");
buffer.push("<div><span class='title'>" + title + "</span>"); buffer.push("<div><span class='title'>" + title + "</span>");
buffer.push("<span>" + description + "</span></div>"); buffer.push("<span>" + description + "</span></div>");
buffer.push("</a></li>"); buffer.push("</a></li>");
}); });
}
buffer.push("</ul>"); buffer.push("</ul>");