我正在尝试在我的项目中使用淘汰赛 js,所以我尝试了简单的 Hello World 示例,但我无法让它工作。我创建了一个新的 MVC4 项目,只需复制下面的简单绑定就是我的代码
<script src="~/Scripts/knockout-2.1.0.js" type="text/javascript"></script>
<script type="text/javascript">
// Here's my data model
var viewModel = function (first, last) {
this.firstName = ko.observable(first);
this.lastName = ko.observable(last);
//this.fullName = ko.computed(function () {
// Knockout tracks dependencies automatically. It knows that fullName depends on firstName and lastName, because these get called when evaluating fullName.
//return this.firstName() + " " + this.lastName();
//}, this);
};
$(document).ready(function() {
ko.applyBindings(new viewModel("Planet", "Earth")); // This makes Knockout get to work
});
</script>
<div class="liveExample">
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
@*<h2>Hello, <span data-bind='text: fullName'> </span>!</h2>*@
</div>
基本上它只会在文本框上显示模型的值。我已经在我的项目中引用了 knockout.js,但它不起作用我还在我的 BundleConfig.cs 中添加了 knockout js
bundles.Add(new ScriptBundle("~/bundles/knockout").Include("~/Scripts/knockout-2.1.0.js"));
我没工作