2011-05-28 98 views
1

我認爲這將是有趣的檢查Sproutcore了,但我遇到了一個我似乎無法弄清楚的錯誤。我正在跟着最近的NetTuts +教程寫關於框架的微博。我的代碼如下:Sproutcore:無法調用方法'取得'null

Microblog.mainPage = SC.Page.design({ 

mainPane: SC.MainPane.design({ 
    childViews: 'topView postView contentView'.w(), 

    topView: SC.ToolbarView.design({ 
     childViews: 'appName'.w(), 
     layout: { top: 0, left: 0, right: 0, height: 40 }, 
     anchorLocation: SC.ANCHOR_TOP, 

     appName: SC.LabelView.design({ 
      layout: { top: 5, left: 5, width: 100 }, 
      displayValue: "MicroBlog App", 
      layerId: "mb-logo" // html id attribute 
     }) 
    }), 

    postView: SC.View.design({ 
     childViews: 'form'.w(), 
     layout: { top: 40, height: 75 }, 
     backgroundColor: 'white', 

     form: SC.View.design({ 
      childViews: 'postContent post'.w(), 
      layout: { left: 200, right: 200 }, 

      postContent: SC.TextFieldView.design({ 
       layout: { top: 10, left: 10, right: 10, height: 60 }, 
       isTextArea: YES, 
       hint: "What's on your mind?" 
      }), 

      post: SC.ButtonView.design({ 
       layout: { top: 80, right: 10, width: 100 }, 
       title: "Post", 
       isDefault: YES 
      }) 
     }) 
    }), 

    contentView: SC.ScrollView.design({ 
     hasHorizontalScroller: NO, 
     layout: { top: 135, bottom: 0, left: 0, right: 0 }, 
     contentView: SC.ListView.design({ 

     }) 
    }) 
}) 
}); 

但是,由於某種原因,它不會加載的按鈕,當我點擊其中任我buttonView或內容查看推移,我得到以下錯誤在我的控制檯頁面上:

Uncaught TypeError: Cannot call method 'get' of null

我嘗試了谷歌搜索,但沒有運氣。我正在使用Sproutcore 1.6。

感謝

回答

2

顯然問題出在最後一部分:

contentView: SC.ScrollView.design({ 
    hasHorizontalScroller: NO, 
    layout: { top: 135, bottom: 0, left: 0, right: 0 }, 
    contentView: SC.ListView.design({ 

    }) 
}) 

出於某種原因,這兩個意見不能具有相同的名稱。我將其更改爲:

contentView: SC.ScrollView.design({ 
    childViews: 'contentListView'.w(), // do i need this here? 
    hasHorizontalScroller: NO, 
    layout: { top: 150, bottom: 0, left: 0, right: 0 }, 
    contentListView: SC.ListView.design({ 

    }) 
}) 

似乎現在工作正常!

+2

我會認爲,實際問題是需要指定子視圖,而不是子視圖的名稱。 – Blacktiger 2011-05-31 18:43:39

+0

雖然沒有childViews,但它工作正常,所以不太確定。它開始工作時,我改變了名稱,有或沒有childViews。 – cabaret 2011-05-31 19:06:30

2

的NETTUTS SproutCore的應用是建立在SproutCore的1.4

SproutCore的版本之間相當顯著變化。我會認爲這是你的問題。

+0

是的,我意識到這可能是我的問題。仍然不確定如何實際修復它1.6雖然.. – cabaret 2011-05-29 10:24:10

1

你已經解決了這個問題,但是:SproutCore中的錯誤「無法調用方法」得到'null'對它的表面來說是無益的,但它通常意味着代碼中有語法錯誤或者否則在聲明中缺少對象,您試圖調用get()。在你的情況下,我認爲添加childViews屬性是有幫助的,並且還需要明確標註contentView標籤。