Sproutcore:无法调用null的方法'get'

时间:2011-05-28 23:17:07

标签: sproutcore typeerror

我认为检查Sproutcore会很有趣,但我遇到了一个我似乎无法弄清楚的错误。我正在关注最近使用该框架编写微博的NetTuts +教程。我的代码如下:

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或contentView所在的页面时,我在控制台中收到以下错误:

Uncaught TypeError: Cannot call method 'get' of null

我试着谷歌搜索它,但没有运气。我正在使用Sproutcore 1.6。

由于

3 个答案:

答案 0 :(得分:2)

NetTuts sproutcore应用程序基于sproutcore 1.4构建

Sproutcore在版本之间的变化非常显着。我认为这是你的问题。

答案 1 :(得分: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 :(得分:1)

你已经解决了这个问题,但是:SproutCore中的错误“无法调用方法'获取'为空”在它的表面上是非常无益的,但它通常意味着代码中存在语法错误或其他在您尝试呼叫get()的对象的声明中缺少。在您的情况下,我认为添加childViews属性有帮助,并且消除contentView标签的歧义也是必要的。

相关问题