Q: knockout js Uncaught Error: Cannot write a value to a ko.computed unless you specify a 'write' option. In my js i am calling a function on click here is my function 
 function PopulateBranch(branchAreaName) {

    var nodePath = "/content/eng/phone-numbers/jcr:content/content-page/wireframe";

    $.ajax({
        data:  "action="+"getBranch"+  "&nodePath=" + nodePath +  "&nodeName=" + branchAreaName,
        url: '/bin/branchlocator/crud' , 
        dataType: 'json',
        type: 'GET',
        success: function (data) {

            self.PopulateBranch = ko.computed(function(){
                ko.utils.arrayForEach(data, function(item){
                    branchView.Branches.push(new Branch(item));
                });
            });
        },
        error: function (exception) {
            alert("fail");
        }
    });

};

i am calling this function inside a view model but i am getting this error when i call this function
Uncaught Error: Cannot write a value to a ko.computed unless you specify a 'write' option. If you wish to read the current value, don't pass any parameters. 

any solution ??

A: function PopulateBranch(branchAreaName) { ... } is a global function in your code. When you call it for the first time, this happens:


*

*You call PopulateBranch("someAreaName").

*It makes an AJAX call.

*When the AJAX call succeeds, the success handler is called and executes the following code:  self.PopulateBranch = ko.computed(...);. You don't have a variable called self in scope, so it resolves to window.self, which equals window, also known as the global scope. That means that this line of code replaces the old function PopulateBranch(branchAreaName) { ... } with the new ko.computed handler.

*The next time you call PopulateBranch("someAreaName"), you are no longer calling the original PopulateBranch() function, you are calling the ko.computed version.
To fix your problem, you should remove that self.PopulateBranch = ko.computed(...); line and replace it with different code that updates your Branches array. Perhaps you just need this:
success: function(data) {
    ko.utils.arrayForEach(data, function(item) {
        branchView.Branches.push(new Branch(item));
    });
}

By the way, I think you are misunderstanding the use of ko.computed. The BranchAreaViewModel's PopulateBranches should not be a ko.computed either, it can be an ordinary function. ko.computed should be used when you want to compute a value based on another observable value, for example, if you have an observable tracking elapsed time in seconds, you can use a ko.computed to compute a string representation of that elapsed time, knockout will automatically recalculate that string whenever the observable value changes.
