开发者

Curly Bracket Variable in Javascript

I have come across this a lot in ExtJS and I was wondering where it's coming from I have an example like this:

 vi开发者_C百科ew: 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.


it's ah Object with two key-value pairs:
1. key: forceFit, value: true
2. key: groupTextTpl, value: '{text} ({[values.rs.length]} {[values.rs.length > 1 ? "Items" : "Item"]})'
second one is a string btw

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜