Subscribe to observable array for new or removed entry only

As of KnockoutJS 3.0, there’s an arrayChange subscription option on ko.observableArray. var myArray = ko.observableArray([“Alpha”, “Beta”, “Gamma”]); myArray.subscribe(function(changes) { // For this example, we’ll just print out the change info console.log(changes); }, null, “arrayChange”); myArray.push(“newitem!”); In the above callback, the changes argument will be an array of change objects like this: [ { index: 3, … Read more

Binding true / false to radio buttons in Knockout JS

I know this is an old thread, but I was having the same problem and found out a much better solution that was probably added to knockout after this question was officially answered, so I’ll just leave it for people with the same problem. Currently there is no need for extenders, custom binding handlers or … Read more

Get previous value of an observable in subscribe of same observable

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) { });

How to get Selected Text from select2 when using

As of Select2 4.x, it always returns an array, even for non-multi select lists. var data = $(‘your-original-element’).select2(‘data’) alert(data[0].text); alert(data[0].id); For Select2 3.x and lower Single select: var data = $(‘your-original-element’).select2(‘data’); if(data) { alert(data.text); } Note that when there is no selection, the variable ‘data’ will be null. Multi select: var data = $(‘your-original-element’).select2(‘data’) alert(data[0].text); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)