0

我有一个使用 qx.data.marshal.Json.createModel 创建的模型,其中包含一个名为“startDate”的字段,它是一个 Date 实例。我想覆盖 getStartDate 以返回 Date 的副本,而不是模型中的相同 Date 实例。

我看过http://manual.qooxdoo.org/2.1/pages/data_binding/models.html但我只发现“查看 qx.data.store.IStoreDelegate 的 API-Documentation 以查看可用方法以及如何实施它们。”。IStoreDelegate 信息不完整,我不知道如何使用它(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));

我该怎么做?

4

1 回答 1

0

作为回报,我用 mixin 创建了一个委托。

// 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);

混音:

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

});
于 2013-01-22T17:25:04.830 回答