如何在fabricjs中获取对象标识符? [英] How to get an object identifier in fabricjs?

查看:45
本文介绍了如何在fabricjs中获取对象标识符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在fabricjs中获取对象标识符?例如

How to get an object identifier in fabricjs? For example

var text = new fabric.IText('hello world', { left: mouse1X, top: mouse1Y });

ID = text.get???

此标识符应出现在

JSON.stringify(canvas) 
canvas.loadFromJSON() 

标识符应存在于JSON.stringify(canvas)canvas.loadFromJSON()

identifier should be present in the JSON.stringify(canvas) canvas.loadFromJSON()

推荐答案

创建对象时,将选项 id 属性传递给

When you create an object, pass along the options an id attribute:

var obj = fabric.Object({id: 'myid'});

或在运行时添加:

obj.id = 'myid';

保存为JSON时,请使用 propertiesToInclude 参数指定您要保存它:

When saving to JSON use the propertiesToInclude parameter to specify you want to save it:

obj.toJSON(['myid', 'others...']);

canvas.toJSON(['myid', 'others...']);

自动加载.

这篇关于如何在fabricjs中获取对象标识符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆