user2142786
user2142786

Reputation: 1482

Error in knockout js String is not a function

Hi in my app when i click on addfields a form appears and when i try to submit that i am getting an error String is not a function . here is my code for add function

self.addTierFields = function (tier) {
   self.Tiers.push(new Tier({
                bothrate: self.bothrate(),
                compoundratee: self.compoundratee(),
                simplerate: self.simplerate(),
                rate: self.rate() 
   }));
    self.show(true);
};

and here is js fiddle link demo

Upvotes: 0

Views: 967

Answers (2)

James
James

Reputation: 4354

self.bothrate etc are not knockout observables at the time they are accessed in your code. You have them defined in your html and they are just regular strings.

So try this instead:

self.addTierFields = function (tier) {
       self.Tiers.push(new Tier({
        bothrate: self.bothrate,
        compoundratee: self.compoundratee,
        simplerate: self.simplerate,
        rate: self.rate 
       }));
        self.show(true);
    };

Upvotes: 1

DarthCoder
DarthCoder

Reputation: 354

In the snippet bellow

 self.Tiers.push(new Tier({
            bothrate: self.bothrate(),
            compoundratee: self.compoundratee(),
            simplerate: self.simplerate(),
            rate: self.rate()
  }));

There is no bothrate in LoanViewModel, I have also changed a number of things, understand the concepts of scope, meaning of $root,$parent,$data.

here is the new fiddle

http://jsfiddle.net/b81mjt9k/10/

Upvotes: 0

Related Questions