JavaScript中的卷曲括号变量 [英] Curly Bracket Variable in Javascript
问题描述
view:new Ext.grid.GroupingView({
forceFit:true,
groupTextTpl:'{text}({[values.rs.length]} {[values.rs.length> 1? 项目:项目]})'
}),
文字}来自这个功能?它没有被设置为var文本;脚本中的任何地方我可以像普通的字符串那样操纵它吗?任何有关这方面的洞察将是有帮助的,
感谢
一个模板在其他代码的某个地方,该字符串中的{text}将在运行时被替换为一个值。
更新:
好的,看,你可以做任何你想要的任何东西。我没有Ext.js方便,所以我不能给你直接的代码。但是这个参数只是一个匿名对象。 新的
操作会创建一个对象,并将该内容用作内容的一部分。 视图
将成为附加到SOMETHING的属性的名称 - 如果没有其他内容,则命名为窗口对象 - 命名新对象。
如果你想知道它的内容,调试器中的 console.dir
应该转出内容。在这些内容中几乎肯定是一个名为 groupTextTpl
的字符串,这只是一个字符串,你会这样做。
更有可能的是,阅读Ext.js中的模板处理 - 您可以编写代码以使用该模板,并从中创建新的自定义容器。
I have come across this a lot in ExtJS and I was wondering where it's coming from I have an example like this:
view: new Ext.grid.GroupingView({
forceFit:true,
groupTextTpl: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
}),
Where is {text} coming from in this function? It's not been set like var text; anywhere in the script. Can I manipulate it like a normal string? Any insight on this would be helpful,
Thanks
That's a template. Somewhere in the rest of the code, the {text} in that string will be replaced with a value at run time.
Update:
Okay, look, you can do pretty much anything you want with it. I've don't have Ext.js handy so I can't give you straight-up code. but that argument is just an anonymous object. The new
operation there creates an object, and uses that stuff as part of the contents. view
will become the name of an attribute attached to SOMETHING -- to the window object if nothing else -- naming that new object.
If you want to know what's in it, console.dir
in a debugger should dump out the contents. In those contents is almost certainly a string named groupTextTpl
, and that's just a string, do with it as you will.
More probably, though, read up on template processing in Ext.js -- you can probably write code to use that template and make new, customized coipies from it.
这篇关于JavaScript中的卷曲括号变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!