Access/Set an Observer Property With a Dot in the Name in JSViews

拈花ヽ惹草 提交于 2019-12-11 11:43:09

问题


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.

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.

Aka:

path.fileWithoutExt.attrs = Works.

path.fileWithExt.png.attrs = Fails.

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

or:

root.path.{{file.dot}}.more

回答1:


You can't pass in paths like "object['keyName'].foo" as first parameter of setProperty. (That parameter does expect simply dot-separated paths).

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 ); 

Updated jsfiddle: all three work...




回答2:


path["fileWithExt.png"].attrs = Works.



来源:https://stackoverflow.com/questions/23608289/access-set-an-observer-property-with-a-dot-in-the-name-in-jsviews

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!