我有一个用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文档,了解可用的方法以及如何实现它们。” 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));
我该怎么做?
答案 0 :(得分: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);
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());
}
}
});