如何在JointJS模型中序列化计算的attr?

时间:2016-01-27 03:55:50

标签: jointjs

我想限制将JointJS模型写入JSON时序列化的数据。我有很多显示器都是经过计算的。值。

我的元素模式如下所示:

GcmTaskService

加载模型后,我调用joint.shapes.model.Name = joint.dia.Element.extend({ markup: '<g class="rotatable"><text class="name"/></g>', defaults: joint.util.deepSupplement({ type: 'model.Name', modelName: 'UNKNOWN', size: { width: 80, height: 80 }, attrs: { '.name': { 'font-family': 'Arial', 'font-size': 13, } } }, joint.dia.Element.prototype.defaults), // Set the view properties based on the model properties modelToViewAttr: function() { // It is more complicated that this, but this is the basic idea this.attr({'.name' : { text: model.modelName }}); } }); 初始化模型的显示方式(这有点烦人,但它将模型与视图分开)。

序列化后,我得到以下内容:

modelToViewAttr

我希望得到以下内容:

{
    "type": "model.Name",
    "modelName": "UNKNOWN",
    "size": {
        "width": 80,
        "height": 80
    },
    "position": {
        "x": 1000,
        "y": 100
    },
    "angle": 0,
    "id": "59c2cd68-eaa9-4bef-8232-fa74b58344ab",
    "z": 6,
    "attrs": {
        ".name": {
            "text": "modelName"
        },
    }
}

请注意,没有{ "type": "model.Name", "modelName": "UNKNOWN", "size": { "width": 80, "height": 80 }, "position": { "x": 1000, "y": 100 }, "angle": 0, "id": "59c2cd68-eaa9-4bef-8232-fa74b58344ab", "z": 6, } 项,因为它是由attrs计算的。

0 个答案:

没有答案