fabricjs - FabricJS - 在添加项目/组时设置 zorder
问题描述
我正在尝试将一组项目添加到画布,但希望在添加时将组设置在 zorder 堆栈的底部。这是我想要做的代码:
//Reload the SVG now
var site_url = "/components/<?=$designObj->svg_filename?>";
fabric.loadSVGFromURL(site_url, function(objects, options) {
let componentObj = fabric.util.groupSVGElements(objects, options);
componentObj.setControlVisible(false);
componentObj.sendToBack(); //THIS DOESNT WORK - THROWS TYPE ERROR
componentObj.selectable = false;
componentObj.jdeation_comp_id = "base";
componentObj.jdeation_base_svg = "<?=$designObj->svg_filename?>";
canvas.add(componentObj).renderAll();
});
调用 sendToBack() 时出现以下错误:
TypeError: Cannot read property 'sendToBack' of undefined
不确定我是否完全理解这里发生的事情,似乎 sendToBack 期望类型不是组或其他东西。有一个更好的方法吗?
解决方案
您不能 .sendToBack()
在尚未添加到画布的对象上。使用canvas.insertAt(componentObj, 0)
而不是canvas.add(componentObj)
指定应将对象添加到堆栈的底部。
推荐阅读
- mysql - 无法部署 MySQL pod。--initialize 指定但数据目录中有文件
- xaml - Xamarin 表单 - 设置默认 TextColor
- python - Python:将函数应用于 netCDF/numpy 3d 数组中的每个条目
- sublimetext3 - 如何在 Sublime 搜索中包含文件夹?
- dart - 剪裁后材料标高不起作用
- python - 将新列从另一个表连接到 redshift/sql 表
- mysql - 用外键删除其他数据
- c++ - 打印信息时数据结构不起作用
- sql - 分组以便将行结果转换为分组列
- d3.js - 无法使用 parseFloat 方法将字符串转换为数字