存储在变量中的关联数组中的访问键
Access Key in Associative array which is stored in variable
我目前正在处理这个问题。我有一个关联数组 imageDict={}。这个 imageDict 的键是另一个名为 image 的对象,值是另一个关联数组,string 作为键,array 作为价值。所以 imageDict[image] = {},并且 imageDict[image]["string"] = [].
我遇到的问题是键 image 是一个对象,其中还存储了一些 key/values 例如,width,height,顶部、左侧 等等。在某些时候 我将 imageDict[image] 存储到 var animationQueue 并将其作为参数发送到 function animation(animationQueue),在那里我访问它的值作为 animationQueue["string"]... 但是我想做的也是访问隐藏在 animationQueue 中的 Key image,因为 animationQueue = imageDict [image] 并更改它的一些值。可以这样做吗?
如果您需要访问图像对象,为什么不将其作为第二个参数传递给您的函数 function animation(animationQueue, image)
,或者您不能更改动画函数吗?我不相信有一种方法可以像你一样将关联数组的值传递给函数,并从值中获取键。该值本身并不存储对键的引用。
我目前正在处理这个问题。我有一个关联数组 imageDict={}。这个 imageDict 的键是另一个名为 image 的对象,值是另一个关联数组,string 作为键,array 作为价值。所以 imageDict[image] = {},并且 imageDict[image]["string"] = [].
我遇到的问题是键 image 是一个对象,其中还存储了一些 key/values 例如,width,height,顶部、左侧 等等。在某些时候 我将 imageDict[image] 存储到 var animationQueue 并将其作为参数发送到 function animation(animationQueue),在那里我访问它的值作为 animationQueue["string"]... 但是我想做的也是访问隐藏在 animationQueue 中的 Key image,因为 animationQueue = imageDict [image] 并更改它的一些值。可以这样做吗?
如果您需要访问图像对象,为什么不将其作为第二个参数传递给您的函数 function animation(animationQueue, image)
,或者您不能更改动画函数吗?我不相信有一种方法可以像你一样将关联数组的值传递给函数,并从值中获取键。该值本身并不存储对键的引用。