Commit 3f1b6be7 authored by Aaron-P's avatar Aaron-P

Check if other bindings exist before trying to attach

parent 6dabdcbf
...@@ -19,51 +19,57 @@ ...@@ -19,51 +19,57 @@
$element.multiselect(config); $element.multiselect(config);
var options = allBindings.get('options'); if (allBindings.has('options')) {
if (ko.isObservable(options)) { var options = allBindings.get('options');
ko.computed({ if (ko.isObservable(options)) {
read: function() { ko.computed({
options(); read: function() {
setTimeout(function() { options();
var ms = $element.data('multiselect'); setTimeout(function() {
if (ms) var ms = $element.data('multiselect');
ms.updateOriginalOptions();//Not sure how beneficial this is. if (ms)
$element.multiselect('rebuild'); ms.updateOriginalOptions();//Not sure how beneficial this is.
}, 1); $element.multiselect('rebuild');
}, }, 1);
disposeWhenNodeIsRemoved: element },
}); disposeWhenNodeIsRemoved: element
});
}
} }
//value and selectedOptions are two-way, so these will be triggered even by our own actions. //value and selectedOptions are two-way, so these will be triggered even by our own actions.
//It needs some way to tell if they are triggered because of us or because of outside change. //It needs some way to tell if they are triggered because of us or because of outside change.
//It doesn't loop but it's a waste of processing. //It doesn't loop but it's a waste of processing.
var value = allBindings.get('value'); if (allBindings.has('value')) {
if (ko.isObservable(value)) { var value = allBindings.get('value');
ko.computed({ if (ko.isObservable(value)) {
read: function() { ko.computed({
value(); read: function() {
setTimeout(function() { value();
$element.multiselect('refresh'); setTimeout(function() {
}, 1); $element.multiselect('refresh');
}, }, 1);
disposeWhenNodeIsRemoved: element },
}).extend({ rateLimit: 100, notifyWhenChangesStop: true }); disposeWhenNodeIsRemoved: element
}).extend({ rateLimit: 100, notifyWhenChangesStop: true });
}
} }
//Switched from arrayChange subscription to general subscription using 'refresh'. //Switched from arrayChange subscription to general subscription using 'refresh'.
//Not sure performance is any better using 'select' and 'deselect'. //Not sure performance is any better using 'select' and 'deselect'.
var selectedOptions = allBindings.get('selectedOptions'); if (allBindings.has('selectedOptions')) {
if (ko.isObservable(selectedOptions)) { var selectedOptions = allBindings.get('selectedOptions');
ko.computed({ if (ko.isObservable(selectedOptions)) {
read: function() { ko.computed({
selectedOptions(); read: function() {
setTimeout(function() { selectedOptions();
$element.multiselect('refresh'); setTimeout(function() {
}, 1); $element.multiselect('refresh');
}, }, 1);
disposeWhenNodeIsRemoved: element },
}).extend({ rateLimit: 100, notifyWhenChangesStop: true }); disposeWhenNodeIsRemoved: element
}).extend({ rateLimit: 100, notifyWhenChangesStop: true });
}
} }
ko.utils.domNodeDisposal.addDisposeCallback(element, function() { ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment