我在 ASP.NET MVC 中研究 Knockoutjs。我收到此错误“未捕获的错误:NOT_FOUND_ERR:DOM Exception 8”......知道吗?谢谢。
在我的 _Layout.cshtml 文件中,这些是我的脚本..
<script src="../../Scripts/modernizr-2.5.3.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.20.min.js" type="text/javascript"></script>
<script src="../../Scripts/knockout-2.1.0.debug.js" type="text/javascript"></script>
<script src="../../Scripts/ajax-util.js" type="text/javascript"></script>
<script src="../../Scripts/bp-index.js" type="text/javascript"></script>
<script src="../../Scripts/ko-execute-on-enter.js" type="text/javascript"></script>
<script src="../../Scripts/ko-protected-observable.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.unobtrusive-ajax.min.js" type="text/javascript"></script>
这是我的模板……
<ul data-bind="foreach: tags">
<li class="tagItem" data-bind="click: $parent.selectTag">
<div>
<span data-bind="text: Name"></span>
<a href="#" class="tag-edit">Edit</a>
<a href="#" class="tag-delete">Delete</a>
</div>
</li>
</ul>
这是我的 js 文件(带淘汰赛)
$(function () {
var data = [
// data
];
var viewModel = {
tags: ko.observableArray(data),
tagToAdd: ko.observable(""),
selectedTag: ko.observable(null),
addTag: function () {
this.tags.push({ Name: this.tagToAdd() });
//var newTag = { Name: viewModel.tagToAdd() };
this.tagToAdd("");
},
selectTag: function () {
console.log("inside selectTag");
viewModel.selectedTag
}
};
$(document).on("click", ".tag-delete", function () {
var itemToRemove = ko.dataFor(this);
viewModel.tags.remove(itemToRemove);
});
ko.applyBindings(viewModel);
});