"TypeError: object is not a function" when using knockout and breeze

Problem

I have < TypeError: the object is not a function of "at EntityManager.saveChanges. An error occurs when the breeze sends something to the server.

When I read the (long) stack trace, I see that the error is being called inside the Breeze method called InitializeEntityPrototype.prototype.getProperty.

There are other places where you may encounter this error; it's just the place i discovered today.

Cause

Please note that my application uses Knockout (ko). This means that my object model is controlled by the "ko" model adapter, which expects each data property to be ko.observable (a observableor observableArray). This means that your property values ​​are implemented as functions , not primitive data types, arrays, or objects.

Breeze initializes my objects with observable properties, so I don't need to do this on my own. But I need to keep these observables when I install entity models in my code .

One of the most common mistakes in ko programming is to set a property, rather than invoke a property setting tool.

todo.Description("foo");  // Correct ... call the ko.observable assignment function
todo.Description = "foo"; // WRONG ... wipes out the observable function !!!

, "foo" todo.Description, ... Breeze .

HTML . ; . . . .

, .

, . , ko. Breeze ko ... , , , . () getProperty:

proto.getProperty = function (propertyName) {
  return this[propertyName]();
};

, , this[propertyName] - , .

, , , - . " " ( - ) . .

S.O. .

?

. , entity ... .

. . , , .

"" breeze.debug.js try/catch.

  • breeze.debug.js
  • "return this[propertyName]();"
  • :

    proto.getProperty = function(propertyName) {
      try {
        return this[propertyName]();
      } catch (err) {
        debugger;
        err.message = propertyName + ' is not a ko function; did you wipe it out by assignment?\n' + 
                      (err.message || '');
        throw err;
      }
    }
    
  • , < >

debugger, .

?

, . , .

. getProperty setProperty . , . . , , , , () Breeze.

.

+4
1

, , . , , , .

...

" ": , , MVVM. , data-bind="visible: !myObservable" .

: , , , , . , , , :

  • Typescript . Description KnockoutObservable<string>, , .
  • : . . ...
  • MVVM, "". AFAIK, , Angular "", , Knockout; .

2 cts - , ( " X Y?" ) - .

+3

Source: https://habr.com/ru/post/1569479/


All Articles