javascript snytax error

Robb Hill
Robb Hill used Ask the Experts™
on
Can anyone see an issue with the syntax here?
The code compiles ...just complains that the syntax is not proper.
The error seems to be at the end of this line -
 isExpanded: <%= Model.ExpandYearCategoryTree ? "true" : "false" %>
                });

Here is the script:


<script type="text/javascript">        
        <% if (Model.ShowYearCategoryTree)
        { %>
        require(['ListDocs/yearCategoryTreeViewModel'], function(viewModel) {
            viewModel.init({
                years: [ <%= String.Join(",", Model.YearCategoryTreeYears) %>],
                fileAreaSiteId: <%= Model.SiteId %>,
                subscriberId: <%= Model.UserSessionVariables.SubscriberId %>,
                isExpanded: <%= Model.ExpandYearCategoryTree ? "true" : "false" %>
                });
        });
        <% } %>
        require(['ListDocs/fileDrop'], function(fileDrop) {
            fileDrop.init({
                fileDropPanel: document.body,
                subscriberId: <%= Model.UserSessionVariables.SubscriberId %>,
                getAddFilesData: function($fileDropItem) {
                    var data = { fileAreaSiteId: <%= Model.SiteId %> };
                        
                    if($fileDropItem.hasClass("jqgrow")) {
                        data.documentId = $fileDropItem[0].id;
                    }

                    return data;
                }
            });             
        });               
    </script>    

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Dave BaldwinFixer of Problems
Most Valuable Expert 2014
Commented:
Look at the "View Source" in the page to see if you are getting what you're expecting.
Top Expert 2015
Commented:
Ternary operations have to be assigned in C#. They cannot be standalone statements.

I'm wondering if you can just cast the boolean to a string.

<%= Model.ExpandYearCategoryTree.ToString() %>
Robb HillSenior .Net Full Stack Developer

Author

Commented:
no its a boolean
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Top Expert 2015
Commented:
I know it's a boolean but if the isExpanded property requires a string value...
Robb HillSenior .Net Full Stack Developer

Author

Commented:
I dont know..its strange...if I end it with a comma the error goes away..but am not sure how thats effecting the code..as that does not seem like proper syntax
Top Expert 2015
Commented:
Have you looked at the source of the rendered page as Dave suggested? What (if anything) is being filled in for the isExpanded value?

What you are really lacking in that whole initializer are default values in case the inline server side code produces nothing. Emptiness is not a valid value in a javascript Object array. If any of those inline code blocks produce nothing, your javascript will fail.
Robb HillSenior .Net Full Stack Developer

Author

Commented:
thanks
Top Expert 2015

Commented:
You're welcome. Glad to help. Thanks for the points.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial