【问题标题】:When to use square brackets and curly brackets in sencha touch?sencha touch 什么时候使用方括号和大括号?
【发布时间】:2013-04-18 05:36:33
【问题描述】:

这可能是一个愚蠢的问题,但这里是。

我一直在 sencha touch 2 应用程序上关注 this tutorial。我对 Ext JS 很陌生,我不明白何时使用 square brackets : [ .. ]curly brackets : { .. }

Ext.define("NotesApp.view.NotesListContainer", {
    extend: "Ext.Container",
    config: {
        items: [{
            xtype: "toolbar",
            docked: "top",
            title: "My Notes",
            items: [{
                xtype: "spacer"
            }, {
                xtype: "button",
                text: "New",
                ui: "action",
                id:"new-note-btn"
            }]
        }]
    }
});

喜欢这里

html: [
                        '<img src="http://staging.sencha.com/img/sencha.png" />',
                        '<h1>Welcome to Sencha Touch</h1>',
                        "<p>You're creating the Getting Started app. This demonstrates how ",
                        "to use tabs, lists and forms to create a simple app</p>",
                        '<h2>Sencha Touch 2</h2>'
                    ].join("")
  1. 在编码 sencha touch 时,谁能帮助我正确使用大括号和方括号?

  2. 为什么不直接使用大括号 { .. } 呢?为什么 ext js 必须使用 [ .. ] 和 { .. }?

【问题讨论】:

  • 上一门基本的 javascript 课程可能对您来说很有趣。因为这些东西是非常基本和必不可少的。 nfriedly.com/techblog/2009/06/…
  • 好吧,我做了 w3schools 基础课程...没有遇到这样的大括号..无论如何,感谢您的链接,我会通过它。在开始接触煎茶之前,我还应该讨论其他任何“基本”主题吗?

标签: extjs sencha-touch sencha-touch-2


【解决方案1】:

这只是基本的 javascript。

[] 表示数组,{} 表示对象字面量,所以:

[{
    xtype: 'foo'
}, {
    xtype: 'bar'
}]

是一个对象字面量数组。

【讨论】:

    猜你喜欢
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    • 2012-09-02
    • 1970-01-01
    相关资源
    最近更新 更多