2013-04-18 123 views
1

這可能是一個愚蠢的問題,但在這裏。何時在方格中使用方括號和大括號?

我一直在關注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. 誰能幫我正確使用捲曲,括號,而編碼煎茶觸摸?

  2. 爲什麼不直接用花括號{..}爲什麼ext js必須和{..}一起使用[..]?

+1

你可能會感興趣的是採取一個基本的JavaScript課程。因爲這些東西是非常基本和必不可少的。 http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/ – 2013-04-18 06:46:50

+0

好吧,我做了w3schools的基本課程......沒有遇到像這樣的大括號。總之,感謝您的鏈接,我會通過它。除了陷入煎茶之前,還有其他什麼「基本」話題應該討論嗎? – 2013-04-18 06:54:31

回答

2

這只是基本的JavaScript。

[]裝置陣列,所述{}裝置的對象常量,所以:

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

是對象文字的陣列。