Bind to simple array of strings
From the documentation, the answer is: When using a template: ${$data} When not using a template: $data
From the documentation, the answer is: When using a template: ${$data} When not using a template: $data
You need to remove the bindings before you use applyBindings again: ko.cleanNode($element[0]);
Actually used this today – to unwrap the observable I had to do: <button data-bind=”attr: { id: ‘prefix_’ + $index() }”> Send </button> Hope this helps.
I realized my first answer missed your point, and won’t solve your issue. The problem is that a computed will only reevaluate if there is some observable that forces it to re-evaluate. There is no native way to force a computed to re-evaluate. However, you can get around this with some hackery by creating a … Read more
ko.subscribable.fn.subscribeChanged = function (callback) { var oldValue; this.subscribe(function (_oldValue) { oldValue = _oldValue; }, this, ‘beforeChange’); this.subscribe(function (newValue) { callback(newValue, oldValue); }); }; Use the above like this: MyViewModel.MyObservableProperty.subscribeChanged(function (newValue, oldValue) { });
Actually you want to find whether the event is triggered by user or program , and its obvious that event will trigger while initialization. The knockout approach of adding subscription won’t help in all cases, why because in most of the model will be implemented like this init the model with undefined data , just … Read more
An observableArray exposes an indexOf function (wrapper to ko.utils.arrayIndexOf). This allows you to do: if (myObservableArray.indexOf(itemToAdd) < 0) { myObservableArray.push(itemToAdd); } If the two are not actually a reference to the same object and you want to run custom comparison logic, then you can use ko.utils.arrayFirst like: var match = ko.utils.arrayFirst(myObservableArray(), function(item) { return itemToAdd.id … Read more
Look at DefinitelyTyped. “TypeScript type definitions repository for popular JavaScript libraries”
You can’t call something on the entire viewModel, but on an individual observable you can call myObservable.valueHasMutated() to notify subscribers that they should re-evaluate. This is generally not necessary in KO, as you mentioned.
When using an observable in an expression you need to access it as a function like: visible: !charted()