Hey everyone, probably an obvious answer to some o...
# suitecommerce
m
Hey everyone, probably an obvious answer to some of you but I'm trying to populate a list on a page with search or query results. I have a helper script that has static values and those are called by the template for the page but I'm not seeing in documentation on how I can populate a list with dynamic values due to the lists being in a JS file and not a SuiteScript file. Does anyone have any resources they can point me to steer me in the right direction?
b
Not exactly sure what your asking, but maybe your looking for
{{#each yourData}} <span>name</span> {{/each}}
which is how its done with handlebars in the templates where yourData is set on the view's getContext
m
For the getContext, can I point
yourData
to a function in a SuiteScript?
b
Check out this article it's a good sample for fetching data with suitescript and exposing it on the frontend: https://developers.suitecommerce.com/develop-your-first-extension.html
m
Thanks Bryce. Super new to everything SuiteCommerce
👍 1
Hey @Bryce Krah I think I'm like... 90% of the way there. I have my function in SuiteScript that is fetching the data from NetSuite. And I'm seeing in the getContext function where I have this already setup. But the getContext only seems to work with functions in other JS files like the one I have below. I've tried setting up the SuiteScript file in the define but it seems like I'm missing some setups. To clarify I already have a GET setup and that is populating the table in some of the views, but I need this search function I have setup to populate a drop down list. Similar to the static lists I have in the function below
Thanks for any assistance
b
Your view would look something like this usually
Copy code
initialize: function () {
        this.model = new YourCustomModelToFetchNS();
      },

      beforeShowContent: function () {
        return this.model.fetch();
      },

      getContext: function getContext() {
        return {
          something: this.model.get('something')
        };
      }
m
I have that setup in my Edit.View.js file
Copy code
initialize: function initialize () {
            this.model = new ContractsExtensionPOC3ContractLinesModel();
        },

        beforeShowContent: function beforeShowContent () {
            this.childViews = {
                'ContractsExtensionPOC3.ContractLines.Form.View': function () {
                    return new ContractsExtensionPOC3ContractLinesFormView({
                        model: this.model
                    });
                }
            };

            if (!!Number(this.options.routerArguments[0])) {
                this.getBreadcrumbPages = function () {
                    return [
                        {
                            text: Utils.translate('Contract Lines'),
                            href: '/contractlines'
                        },
                        {
                            text: 'Edit'
                        }
                    ];
                };

                this.title = Utils.translate('Edit Contract Line');

                return this.model.fetch({
                    data: {internalid: this.options.routerArguments[0]}
                });
            }
            else {
                this.getBreadcrumbPages = function () {
                    return [
                        {
                            text: Utils.translate('Contract Lines'),
                            href: '/contractlines'
                        },
                        {
                            text: 'Add'
                        }
                    ];
                };

                this.title = Utils.translate('Add Contract Line');

                return jQuery.Deferred().resolve();
            }
        },

        getContext: function getContext () {
            return {
                isNew: this.model.isNew()
            };
        },