使用JSViews中的名称访问/设置带有点的Observer属性 [英] Access/Set an Observer Property With a Dot in the Name in JSViews
问题描述
我相信标题&我简化的 jsFiddle示例解释了我的困境.
I believe the title & my simplified jsFiddle Example explains my predicament.
基本上,我要处理的是一个非常大的&包含文件夹&的多维观察者对象文件,所有文件都具有动态属性名称.
Basically I am dealing with an extremely large & multidimensional observer object containing folders & files, all of which have dynamic property names.
当涉及到使用Observer setProperty()
函数时,我正在努力寻找一种在属性上带有诸如" file.png "之类的点的属性上使用此方法的方法.显然这是因为当句号出现在set属性路径中时,JSViews认为它在对象树中更深了一步.
When it comes to using the Observer setProperty()
function, I am struggling to find a way to use this on properties with a dot in the name such as "file.png". This is obviously because when the full stop appears in the set property path JSViews believes it to be a step deeper in the object tree.
又是:
path.fileWithoutExt.attrs
=有效.
path.fileWithExt.png.attrs
=失败.
所以我的问题是"是否有一种方法可以实现属性设置,或者不可能或没有功能请求?"可能是这样的:
So my question is "Is there a way to achieve property setting, or is it not possible or a feature request?" Could it be something like:
root.path.[file.dot].more
或:
root.path.{{file.dot}}.more
推荐答案
您不能将"object['keyName'].foo"
之类的路径作为setProperty
的第一个参数传递. (该参数确实只需要点分隔的路径即可.)
You can't pass in paths like "object['keyName'].foo"
as first parameter of setProperty
. (That parameter does expect simply dot-separated paths).
但是您不需要.只需将实际对象传递给$.views.observable(...)
,则只需将叶子属性名称传递给setProperty
:
But you don't need to. Just pass the actual object to $.views.observable(...)
then you only need to pass the leaf property name to setProperty
:
$.observable( files.images[n] ).setProperty( 'modified', 'Modified!' );
$.observable( files.images[n] ).setProperty( 'alias', a );
更新了jsfiddle :这三项工作均...
Updated jsfiddle: all three work...
这篇关于使用JSViews中的名称访问/设置带有点的Observer属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!