Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Without seeing all your code this is hard to be sure, but if the code (as is) works when directly included in generate, then I'd be willing to bet that <code>this</code> is not what you think it is in the <code>test</code> function. <code>this</code> has a different meaning inside the <code>test</code> function than it did inside <code>generate</code>.</p> <p>Fire up Chrome or Firebug and set a breakpoint on the <code>var unmapped = ko.mapping.toJS(this);</code> line. Run your program and when the breakpoint hits go to the Console and look at <code>this</code>. Is it your ViewModel?</p> <p>If <code>this</code> is what you expect inside <code>generate</code> you could always call <code>test</code> like this:</p> <pre><code>test.apply(this); </code></pre> <p>This will explicitly set the context of <code>this</code> for the method invocation.</p> <p>Another option is to set a <code>self</code> variable inside your ViewModel. This is usually done at the top and looks like: <code>var self = this;</code>. By creating this variable you can then reference <code>self' inside any functions within the outer "function" scope, and not have to worry about the value of</code>this` fluctuating.</p> <p>--</p> <p>Here is a simple fiddle to simulate what I think is happening: <a href="http://jsfiddle.net/jearles/aLFWe/" rel="nofollow">http://jsfiddle.net/jearles/aLFWe/</a></p> <p>Open Chrome or Firebug console and look at the logged objects. Note that <code>Window</code> was the logged object when I just called <code>updatea()</code>, but was <code>Object</code> in the original click function and when I called <code>updateb.apply(this)</code> or <code>updatec()</code> (which referenced <code>self</code>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload