简体   繁体   中英

Uncaught Error: NOT_FOUND_ERR: DOM Exception 8

I was working on Knockoutjs in ASP.NET MVC. I m getting this error "Uncaught Error: NOT_FOUND_ERR: DOM Exception 8 "...any idea?? thnx.

In my _Layout.cshtml file these are my scripts..

    <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>

this is my template....

<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>

and this is my js file(with knockout)

$(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);
});

This bit of your code could weel be the source of the error:

   selectTag: function () {             
        console.log("inside selectTag");             
        viewModel.selectedTag         
   } 

I think you need something more along the lines of:

   selectTag: function (tag) {             
        console.log("inside selectTag");             
        viewModel.selectedTag(tag);       
   } 

If it is not this, then basically the error is because some of your JS or HTML is invalid. I would try commenting out lin by line until you find the source of the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM