4

我正在使用 WDDX 将 ColdFusion 结构存储在数据库中,并且我想维护指针。这是一个示例(抱歉,速记符号可能充满错误,因为我几乎从不使用它):

tshirt={color={selected="red",options=["red","blue","yellow","white"]}};
tshirt.front= {colors=tshirt.color,design="triangle",ink="green"};
tshirt.back= {color=tshirt.color,design="square",ink="black"};

现在,tshirt.front.colortshirt.back.colortshirt.color都是指向同一个结构的指针。如果我将tshirt.color.selected更改为“blue”,则 tshirt.back.color.selectedtshirt.front.color.selected也将是“blue”。

但是,假设我 WDDX tshirt然后 unWDDX 它。当我将tshirt.color.selected更改为“白色”时,它不会在tshirt.front.color.selectedtshirt.back.color.selected中更改。

谁能建议另一种方法来序列化和反序列化可以保留指针的数据?

到目前为止,我一直在使用一些链接进行研究:

4

1 回答 1

3

使用ObjectSave(),CF9 中的新功能:

描述

将 ColdFusion 数组、CFC、DateTime 对象、Java 对象、查询或结构转换为可序列化的二进制对象,并可选择将对象保存在文件中。

退货

对象的可序列化二进制表示。

<cfscript>
    shirtdata = objectSave(tshirt);
    tshirt2 = objectLoad(shirtdata);

    tshirt2.color.selected = "blue";
    writeOutput(tshirt2.front.colors.selected);  // "blue" => reference kept
</cfscript>

现场演示:http ://www.trycf.com/scratch-pad/pastebin?id=L0g211aD

于 2014-08-21T22:09:53.427 回答