56 votes

Obtention d'une erreur non capturée "NO_MODIFICATION_ALLOWED_ERR" pour la liaison d'entrée

Je commence avec ceci:

<script src="/Scripts/jquery-1.6.2.min.js" ...
<script src="/Scripts/knockout-1.2.1.debug.js" ...
<script src="/Scripts/knockout.mapping-latest.js" ...
<script src="/Scripts/jquery.unobtrusive-knockout.min.js" ...

Puis je tire un plat d'objet JSON à partir du serveur et lient chacune des biens qui se trouvent à l'appariement des éléments dans le DOM:

$.ajax({
    url: '/GetRecord',
    type: 'POST',
    dataType: 'json',
    data: JSON.stringify(requestObject),
    contentType: 'application/json; charset=utf-8',
    success: function (data) {
        // Clear the current view model
        VM.Items.length = 0;

        // only one item coming from server
        VM.Items[0] = ko.mapping.fromJS(data.BlankItem);

        // for each property found, bind it to the matching DOM element
        $.each(VM.Items[0], function (indexInArray, valueOfElement) {
            var attrName = indexInArray;

            // skip over things not an accessor (get/set property function)
            if( typeof valueOfElement == "function")
            {
                var attrValue = valueOfElement();

                // if it's a checkbox, bind the checked attribute
                var a = $('input[name="' + attrName + '"][type="checkbox"]');
                if (a.length)
                    a.dataBind({ checked: attrName });

                // if it's a radio, bind all the found radio checked attributes
                var b = $('input[name^="' + attrName + '"][type="radio"]');
                if (b.length)
                    b.dataBind({ checked: attrName });

                // if it's a text, bind the text attribute
                var c = $('input[name="' + attrName + '"][type="text"]');
                if (c.length)
                    c.dataBind({ text: attrName });  // <--- Error (use value)
            }
        });

        // Then set knockout loose
        ko.applyBindings( VM.Items[0] );
    }
});

Il en résulte une erreur:

Erreur non interceptée: NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7
ko.bindingHandlers.updateknockout-1.2.1.debug.js:1577
invokeBindingHandlerknockout-1.2.1.debug.js:1231
ko.applyBindingsToNode.ko.dependentObservable.
disposeWhenNodeIsRemovedknockout-1.2.1.debug.js:1268
evaluateknockout-1.2.1.debug.js:927
ko.dependentObservableknockout-1.2.1.debug.js:965
ko.applyBindingsToNodeknockout-1.2.1.debug.js:1252
ko.applyBindingsknockout-1.2.1.debug.js:1284
ko.utils.arrayForEachknockout-1.2.1.debug.js:48
ko.applyBindingsknockout-1.2.1.debug.js:1283
$.ajax.successPropertyForm:266
f.prolonger._Deferred.e.resolveWithjquery-1.6.2.min.js:16
wjquery-1.6.2.min.js:18
f.de soutien.ajax.f.ajaxTransport.envoyer.d

Je ne vois pas la liaison de l'un quelconque des éléments qu'il ne devrait pas. Aussi, il n'y a pas déclarative knock-out des liaisons dans l'html. Ce que je fais mal?

119voto

Dr. Zim Points 7301

OMG. La réponse était d'utiliser l'attribut de liaison approprié. Au lieu de text , c’était value pour une entrée!

1voto

Patrice Calvé Points 411

Dans mon cas, le problème était que je liais les données au texte au lieu de la valeur.

mauvais: <type d'entrée = "texte" data-bind = "texte: id" maxlength = "3" style = "width: 100%;" />

bon: <type d'entrée = "texte" data-bind = "valeur: id" maxlength = "3" style = "width: 100%;" />

0voto

Homer Points 2775

J'ai également constaté cette erreur dans Chrome lorsque j'appelais accidentellement plusieurs fois ko.applyBindings(viewModel) .

Prograide.com

Prograide est une communauté de développeurs qui cherche à élargir la connaissance de la programmation au-delà de l'anglais.
Pour cela nous avons les plus grands doutes résolus en français et vous pouvez aussi poser vos propres questions ou résoudre celles des autres.

Powered by:

X