Snap.format(token, json)
替换{<name>}
结构类型为相应参数形式。
参数
token
字符串。要格式化的字符串。json
对象。该对象属性被用来替换。
返回值
字符串。格式化的字符串。
使用
var str = '<div id="{id}">{content}</div>';
var rep = Snap.format(str, {
id: "id_" + mina.time(),
content: '我正在床上听歌'
});
window.console &&
console.log(rep);
// 结果是:
// <div id="id_1389797097377">我正在床上听歌</div>
// 下面这个画一个矩形形状,代码等同于"M10,20h40v50h-40z"
paper.path(Snap.format("M{x},{y}h{dim.width}v{dim.height}h{dim['negative width']}z", {
x: 10,
y: 20,
dim: {
width: 40,
height: 50,
"negative width": -40
}
}));