Question

I have this type defined:

$data.Entity.extend('MyApp.Models.Vehicle', {
    'ID': { 'key': true, 'type': 'Edm.String', 'nullable': true, 'required': false },
    'Maker': { 'type': 'Edm.String', 'nullable': false, 'required': true },
    'Model': { 'type': 'Edm.String', 'nullable': false, 'required': true },
    'Year': { 'type': 'Edm.Int32', 'nullable': false, 'required': true },
    'LicencePlate': { 'type': 'Edm.String', 'nullable': false, 'required': true },
    'Color': { 'type': 'MyApp.Models.Color', 'nullable': false, 'required': false }
});

And object Color defined like that:

$data.Entity.extend('MyApp.Models.Color', {
    'Name': { 'type': 'Edm.String' },
    'Value': { 'type': 'Edm.Int32', 'nullable': false, 'required': true }
});

When something changes on primitive values, JayData submits the changes. But if something changes on Color or any other (I have many more) custom data type, JayData does not track the changes on those objects...

How can I notify JayData that they changed or enable the tracking (force it?) ?

Was it helpful?

Solution

JayData does NOT track complex types (like arrays or custom type objects) inner values.. It just tracks the reference to the value.

In case you want to force the update in this case, you have to make a "deep copy" or encapsulate you current object into another one for the reference to change. For example using jQuery:

entity.field = jQuery.extend({}, field);

Nothing really changes for your object values, but it gets encapsulated in jQuery's object and the reference has changed, so JayData thinks it's value has changed and sends the updated values to the server.

It is a workaround, but as my friend said: "Do you really care about how much clients' CPU you use?" :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top