ExamplePanel: don't fail when selecting non-existing id

This commit is contained in:
rolux 2012-06-20 11:03:37 +02:00
parent 542be904ea
commit a3f0a38bf2

View file

@ -108,9 +108,9 @@ Ox.ExamplePanel = function(options, self) {
} }
function selectItem(id) { function selectItem(id) {
var item; var item = id ? Ox.getObjectById(self.items, id) : null
if (id) { if (item) {
item = Ox.getObjectById(self.items, id); self.options.selected = id;
self.$panel.replaceElement(1, self.$panel.replaceElement(1,
self.$page = Ox.ExamplePage({ self.$page = Ox.ExamplePage({
height: window.innerHeight, height: window.innerHeight,
@ -129,11 +129,11 @@ Ox.ExamplePanel = function(options, self) {
}) })
); );
} else { } else {
self.options.selected = '';
self.$list.options({selected: []}); self.$list.options({selected: []});
self.$page.empty().append(self.options.element); self.$page.empty().append(self.options.element);
} }
self.options.selected = id; that.triggerEvent('select', {id: self.options.selected});
that.triggerEvent('select', {id: id});
} }
return that; return that;