English 中文(简体)
JavaScript - 作为对象属性通过字符串
原标题:JavaScript - passing string as an object property
  • 时间:2012-05-23 10:09:33
  •  标签:
  • javascript

仅提醒您一下这个代码是 ExtJS 4 脚本的一部分 。 我有一个全球设置, 我用它来显示通往图标所在的目录路径 。 我之前正在做一些修改 :

g_ 设置. iconUrl

但现在我需要通过第三个争论 财产像这样:

g_ 设置. iconUrl.docIcon

我遇到的问题是 我有一个 if 语句, 其中我检查不同的值 :

(extensions succession =================================================================================)

然后我会说:

扩展 + 图标 ;

我需要使用:

g_ 设置. iconUrl.extension

当我使用 conole.log(extension) < its value is as expect(例如 docIcon ),但当我试图使用它作为属性时,它不起作用。 如果我使用控制台。 log on :

console.log(g_ 设置. iconUrl+ . +extensions)

the output is [object Object].docIcon so I think I have to convert somehow extensions to object too. I m not sure that this will solve the problem but that s what I have for now.

有什么建议吗?

谢谢 谢谢

勒伦

最佳回答

何不把它加到绳子上...

conole.log ("g_sections.iconUrl."+示例) ("g_sections.iconUrl."+示例)

问题回答

图标URL 是一个字符串(而且可能仍然是一个字符串), 但是随后您添加了一些属性... 所以在.iconURL= 的指派中...

iconURL.file="...";//(or other name you choose)

以及后一用途

.iconURL.file+"."+extensions;




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签