2011-05-28 102 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标签。