简体   繁体   中英

Trouble implementing NavigationView - Sc.View is not observable

When I try to push a view on the view stack of my NavigationView using

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

It gives me this:

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

Obviously, SC.View is not KVO compliant. Then is it a bug in the SproutCore framework? Because they do this in the SC.NavigationView source:

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

MyApp.MyView looks like this:

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'
        })
    })
});

But I think the SproutCore developers are way smarter and more experienced than I am, so it's probably something I did.

Why doesn't my SC.View subclass have a get() method?

It looks like your view hasn't been created yet, so it's still a class rather than an instance. Classes don't have .get, only instances. If you're getting fancy (definitely encouraged :) ) with passing views around, rather than simply letting the childView hierarchy handle them, you have to create them as well. Try passing in MyApp.MyView.create() instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM