Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用二维数组概念从javascript中选定的矩形检索数据_Javascript_Arrays_Svg - Fatal编程技术网

如何使用二维数组概念从javascript中选定的矩形检索数据

如何使用二维数组概念从javascript中选定的矩形检索数据,javascript,arrays,svg,Javascript,Arrays,Svg,我想从选定的矩形中检索数据。我有许多矩形。如果我选择特定的矩形,将显示特定矩形的数据。我已将矩形的数据存储在一个数组集合中。但我不知道如何检索数据。因为如果我删除3个矩形中的一个矩形矩形数组集合索引已更改 例如,我有两个矩形。矩形的数据存储在一个数组集合中。 像这样 this.model.rectCollection[this.rectIndex]=this.model.selectedData; 这里,每个矩形的矩形索引都发生了变化 我的问题是,我正在使用此代码删除第一个矩形 if(this

我想从选定的矩形中检索数据。我有许多矩形。如果我选择特定的矩形,将显示特定矩形的数据。我已将矩形的数据存储在一个数组集合中。但我不知道如何检索数据。因为如果我删除3个矩形中的一个矩形矩形数组集合索引已更改

例如,我有两个矩形。矩形的数据存储在一个数组集合中。 像这样

this.model.rectCollection[this.rectIndex]=this.model.selectedData;
这里,每个矩形的矩形索引都发生了变化

我的问题是,我正在使用此代码删除第一个矩形

if(this.rectRemovedIndex>-1){
this.model.rectCollection.splice(this.rectRemovedIndex,1);
}
现在rectcollection索引已更改。第二个矩形的数据存储在rectcollection[0]中

我想拖动第二个矩形意味着,对应的rectIndex是1。 因此,所选数据将推送到rectCollection[1]。为第二个添加了索引。但也仅为第二个修改了rectCollection[0]

if (this.dragdrop || this.rectPan) {                
                this.model.rectCollection[this.rectIndex] = 0;
               this.model.rectCollection[this.rectIndex] = this.model.selectedData;            
        }    
这里,rectIndex应该是1.0,因此数据已更改


如何操作。

可能您在拼接时不更新此.rectIndex。对应的rect.rectIndex的值将相同。这不会更改。因为在删除rect时,只有索引更改。如果我不删除,但我将执行拖动操作,则意味着,这个rectIndex值是对应的rect。还有其他可能的解决方案吗?有人建议我吗?这对我应该有很大帮助。也许一些具体的数据可以帮助解决这个问题。