When Migrating a View’s Code to SCView, Where Do I...
# suitecommerce
a
When Migrating a View’s Code to SCView, Where Do I Put the beforeShowContent() Code?
s
beforeShowContent
as a method is only available on a Page Type Base View. Do you intend to use SC View as a layout page? Perhaps you should be using a page type instead, or perhaps you want to elaborate a bit more about what it is you’re trying to do.
a
I am using Page Type Base View as the parent module layout. I want to create a child view in that same page type.
s
So put your beforeShowContent in the parent view or put it in your child view’s initialize method
a
I did that. I am getting collection in my collection view file now but I can't pass models individually to the Details View.
When I log 'options' in my Collection View, I can see that I am getting an object inside which there is a collection with all the models. But when I log 'options.collection', it returns an object with no models and 0 length
s
> but I can't pass models individually to the Details View. Why? > But when I log 'options.collection', it returns an object with no models and 0 length It sounds like you're not waiting for the collection to finish fetching before trying to render its data
a
How do I do that?
s
Well this all depends on how you've structured your code. You typically either use beforeShowContent, which returns something like
this.collection.fetch()
, which will return a deferred object, or you bind a callback to showContent on your view after the fetch is done, eg:
Copy code
collection.fetch().done(function () {
  view.showContent();
});
If you're not familiar with deferred objects, google them, or read this https://developers.suitecommerce.com/jquery-promises-and-deferred-objects.html
a
Untitled.js
This is my List View file. Instead of PageTypeBaseView, I am using SCView component. As per your suggestion, I put the beforeShowConent where the initialization code is. As I said, in the collection view file, I am unable to access the collection sent through List View. I have been using the references from the documentations you sent above but can't pinpoint the actual issue.
s
Well I would reiterate my suggestion that if this is a list view, ie a layout page, then you should use the page type base view. That way you can just use beforeShowContent. The problems with this code are myriad. Firstly, getContext should not return a collection — getContext is to return a context object that is sent to the template so that its output can be rendered. If you want to pass the template the entire collection, that is fine, but I don’t think that’s what you’re intending because you are also trying to render a child view with the collection. Secondly, you still haven’t done anything to make the application wait for the fetch to complete. My recommendation is that you go through the tutorials, both on the site, the help center documentation, and, if possible, the learning center (ie get an LCS pass) as I’m not sure you’re really ‘getting’ this, and it’s probably too soon for you to dive in with custom code.