
出现错误“无法读取未定义的属性’async’”,因为找不到“ klass”-https:
//github.com/kangax/fabric.js/blob/master/src/util/misc.js#L214
-215。
您必须将自定义对象分配给
fabric对象-否则
canvas.loadFromJSON()不起作用。
var fabric.CustomGroup = fabric.util.createClass(fabric.Group, { type : 'customGroup', initialize : function(objects, options) { options || ( options = { }); this.callSuper('initialize', objects, options); this.set('customAttribute', options.customAttribute || 'undefinedCustomAttribute'); }, toObject : function() { return fabric.util.object.extend(this.callSuper('toObject'), { customAttribute : this.get('customAttribute') }); }, _render : function(ctx) { this.callSuper('_render', ctx); }});另外,您必须声明该
fromObject方法-是必需的
loadFromJSON。在这种情况下,您的对象是负载同步的。
fabric.CustomGroup.fromObject = function (object, callback) { var _enlivenedObjects; fabric.util.enlivenObjects(object.objects, function (enlivenedObjects) { delete object.objects; _enlivenedObjects = enlivenedObjects; }); return new fabric.CustomGroup(_enlivenedObjects, object);};如果您的自定义对象是异步加载的,则必须执行以下 *** 作:
fabric.CustomGroup.fromObject = function (object, callback) { fabric.util.enlivenObjects(object.objects, function (enlivenedObjects) { delete object.objects; callback && callback(new fabric.CustomGroup(enlivenedObjects, object)); });};fabric.CustomGroup.async = true;我做了一个小的jsfiddle测试用例:http :
//jsfiddle.net/Kienz/qPLY6/
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)