[英]How to correctly include jQuery with knockout.js in ASP.NET MVC5
I created an MVC project in VisualStudio 2017. 我在VisualStudio 2017中创建了MVC项目。
Edit: I updated knockout aand jQuery to newest versions. 编辑:我将淘汰赛和jQuery更新到最新版本。
I have included my .js file at the bottom and it works fine until I try to use jQuery. 我在底部包含了.js文件,在我尝试使用jQuery之前,它可以正常工作。
In my .js file: 在我的.js文件中:
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. 并且页面吐出2
<li>
并带有文本$ {$ data.name}对我来说意味着不包括jQuery。 I am able to use jQuery in the console. 我可以在控制台中使用jQuery。
Thanks for any help! 谢谢你的帮助!
Knockout templating works through regular knockout data binding. 敲除模板通过常规的敲除数据绑定工作。
<ul data-bind="template: {name:'jobsTemplate', foreach: jobs}"></ul>
<script id="jobsTemplate" type="text/html">
<li data-bind="text: name"></li>
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.