Javascript 删除使用paperJS创建的特定形状

Javascript 删除使用paperJS创建的特定形状,javascript,html,html5-canvas,paperjs,Javascript,Html,Html5 Canvas,Paperjs,我创建了一个简单的图像标记,包括圆形、矩形和直线。如何删除我不需要的形状。我已将坐标点存储在阵列中。我怎样才能得到任何帮助 下面是推入数组的函数 function onMouseUp(event) { console.log(cPath.points[0]); console.log(cPath.downpoints[0]); if(set == 1){ i++;

我创建了一个简单的图像标记,包括圆形、矩形和直线。如何删除我不需要的形状。我已将坐标点存储在阵列中。我怎样才能得到任何帮助

下面是推入数组的函数

function onMouseUp(event) {
            console.log(cPath.points[0]);
            console.log(cPath.downpoints[0]);
            if(set == 1){
                i++;
                circles.push(circle);
                createElem('circle', i);
                cPath.points.push(event.point);
                cPath.downpoints.push((event.downPoint - event.point).length);
            }else if(set == 2){             j++;
                rects.push(rect);
                createElem('rect', j);
            }else if(set == 3){
                k++;
                lines.push(line);
                createElem('line', k);  
            }else if(set == 4){
                l++;
                createElem('Free Path', l);
            }
        };
根据路径,将从paperjs文档中删除路径

当您将所有项目(路径)保存在数组中时,将它们从画布中移除相对容易。下面是一个示例javascript片段,它将删除给定数组中的所有项:

function removeItems(items) {
    var len = items.length;
    while(--len < -1) {
       // remove item from the document using paperjs method
       items[len].remove();
       // also remove the item from our own array
       items.splice(len, 1);
    }
}

我不是这个意思。所有的形状都应该有选择地呈现,我必须删除一个圆形或矩形等,对不起,如果你不是这个意思,我无法理解你需要什么。你想每组只画一张吗?还是在画圆圈时隐藏其他人?请你再解释一下这个用例好吧,举个例子,我画了5个圆圈,命名为circle1,circle2,等等,同样的,我画了5个矩形,命名为rect1,rect2,等等,现在我只想删除circle2。你能理解吗。只要在循环中做一个if语句,只删除具有给定名称的项。。。我编辑的功能,小提琴还是旧的。此外,在问题代码中,您实际上没有命名任何路径。因此,在按名称删除它们之前,您应该首先命名它们。
function removeItems(items, name) {
    var len = items.length;
    while(--len < -1) {
       if(items[len].name == name) {
            // remove item from the document using paperjs method
            items[len].remove();
            // also remove the item from our own array
            items.splice(len, 1);
       }
    }
}
removeItems(circles, 'circle1');