0

I created an MVC project in VisualStudio 2017.

Edit: I updated knockout aand jQuery to newest versions.

I have included my .js file at the bottom and it works fine until I try to use jQuery.

In my .js file:

function job(name) {
    return {
        name: ko.observable(name)
    };
}

var viewModel = {
    jobs: ko.observableArray([new job("johnny"), new job("anderson")]),

    addJob: function () {
        this.jobs.push(new job("Another job"));
    },
}
ko.applyBindings(viewModel);

the markup:

<script src="~/Scripts/jquery-3.3.1.min.js"></script>
<script src="~/Scripts/knockout-3.4.2.js" type="text/javascript"></script>


<h3>Jobs:</h3>
<ul data-bind="template: {name:'jobsTemplate', foreach:jobs}"></ul>

<script id="jobsTemplate" type="text/html">
    <li>${ $data.name }</li>
</script>

and the page spits out 2 <li> with the text ${ $data.name } meaning to me that jQuery isn't included. I am able to use jQuery in the console.

Thanks for any help!

Jahni Slim
  • 21
  • 6
  • What version of JQuery are you trying to load? – Jason Spake Mar 01 '18 at 20:32
  • Also is there any particular reason you're using such an old version of knockout? – Jason Spake Mar 01 '18 at 20:34
  • Possible duplicate of [Knockout 2.2.0 error with jQuery 1.9](https://stackoverflow.com/questions/14475781/knockout-2-2-0-error-with-jquery-1-9) – Jason Spake Mar 01 '18 at 20:36
  • It's the version that loaded into the Scripts file via NuGet.. lemme look at that. Wow, jQuery was really old too.. Now I know to check updates via NuGet. – Jahni Slim Mar 01 '18 at 20:43
  • That syntax `
  • ${ $data.name }
  • ` isn't something that is natively supported by either knockout or jquery as far as I know. Are you using handlebars.js? – Jason Spake Mar 01 '18 at 21:22
  • 1
    There's the problem, Jason! I didn't realize that syntax wasn't built into knockout. You have to add a template library, like handlebars, mustache or, in this case, jquery.tmpl Thanks so much! – Jahni Slim Mar 01 '18 at 21:39
  • you're welcome! – Jason Spake Mar 01 '18 at 21:40