1

当我尝试使用 NavigationView 的视图堆栈上推送视图时

MyApp.getPath('mainPage.mainPane.content.nav').push(MyApp.MyView);

它给了我这个:

Uncaught TypeError: Object function (props) {
      this.__sc_super__ = ret.prototype;
      return this._object_init(props);
    } has no method 'get'

显然,SC.View 不兼容 KVO。那么是不是 SproutCore 框架的 bug 呢?因为他们在 SC.NavigationView 源代码中执行此操作:

view.get("topToolbar"); // with `view` being the view I passed in as shown above

MyApp.MyView看起来像这样:

MyApp.MyView = SC.View.extend({
    childViews: 'search results'.w(),

    search: SC.TextFieldView.design({
        layout: { centerX: 0, top: 40, width: 400, height: 30 },
        hint: "Search"
    }),

    results: SC.TemplateView.design({
        templateName: 'results'
    }),

    topToolbar: SC.NavigationBarView.design({
        childViews: ['title'],
        layout: { height: 44 },
        title: SC.LabelView.design({
            controlSize: SC.LARGE_CONTROL_SIZE,
            layout: { width: 100, height: 24, centerX: 0, centerY: 0 },
            value: 'Title'
        })
    })
});

但我认为 SproutCore 开发人员比我更聪明、更有经验,所以这可能是我做的。

为什么我的SC.View子类没有get()方法?

4

1 回答 1

1

看起来你的视图还没有创建,所以它仍然是一个类而不是一个实例。类没有.get,只有实例。如果您喜欢(绝对鼓励 :) )传递视图,而不是简单地让 childView 层次结构处理它们,您还必须创建它们。尝试传入 MyApp.MyView.create() 代替。

于 2013-06-08T16:09:45.777 回答