【问题标题】:Sproutcore: Cannot call method 'get' of nullSproutcore:无法调用 null 的方法“get”
【发布时间】:2011-09-04 03:07:23
【问题描述】:

我认为检查 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。

谢谢

【问题讨论】:

    标签: sproutcore typeerror


    【解决方案1】:

    NetTuts sproutcore 应用基于 sproutcore 1.4 构建

    不同版本之间的 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({
    
        })
    })
    

    现在似乎可以正常工作了!

    【讨论】:

    • 我认为实际的问题是需要指定子视图,而不是子视图的名称。
    • 它在没有 childViews 的情况下工作得很好,所以不太确定.. 当我更改名称时它开始工作,无论有没有 childViews。
    【解决方案3】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多