0

I have a model created with qx.data.marshal.Json.createModel that contains a field named "startDate" which is a Date instance. I would like to override the getStartDate in order to return a copy of the Date and not the same Date instance in the model.

I've seen http://manual.qooxdoo.org/2.1/pages/data_binding/models.html but I only found "Take a look at the API-Documentation of the qx.data.store.IStoreDelegate to see the available methods and how to implement them.". The IStoreDelegate info is not complete and I don't know how to use it (http://demo.qooxdoo.org/2.1/apiviewer/index.html#qx.data.store.IStoreDelegate).

var delegate = {
    getModelMixins : function(properties) {

    }
};

var marshaler = new qx.data.marshal.Json(delegate);
marshaler.toClass(data);
var model = marshaler.toModel(data);
// the problem with weeks is that someone changes the dates
// we must make the getFromDay to return a copy of the data
weeks.append(qx.data.marshal.Json.createModel(weeksRaw));

How might I do it?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Totty.js
  • 15,563
  • 31
  • 103
  • 175

1 Answers1

0

I've created a delegate with the mixin in return.

// notice the _ variables
weeksRaw.push({
     label: "week: " + weeksNum + ' [' + startDayString + '-' + endDayString + '['
    ,_fromDay: week.startDay
    ,_toDay: week.endDay
});
var delegate = {
    getModelMixins : function(properties) {
        return myapp.models.marshalMixins.Week;
    }
};
var marshaler = new qx.data.marshal.Json(delegate);
marshaler.toClass(weeksRaw);
var model = marshaler.toModel(weeksRaw);

The mixin:

qx.Mixin.define('production.models.marshalMixins.Week', {
    members: {
        getFromDay: function(){
            return new Date(this.get_fromDay());
        }
        ,getToDay: function(){
            return new Date(this.get_toDay());
        }
    }

});
Totty.js
  • 15,563
  • 31
  • 103
  • 175