111

Вопрос по javascript – Как очистить / удалить наблюдаемые привязки в Knockout.js?

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Все идет нормально.

Error: User Rate Limit Exceeded

  1. The markup shows the previous object/model as well as the new object/model.
  2. A javascript error occurs relating to one of the properties in the object/model, although it's still rendered in the markup.

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

EDIT

Error: User Rate Limit Exceeded

mn.AccountCreationModel = new AccountViewModel(jsonData.Account);
ko.applyBindings(mn.AccountCreationModel);

Error: User Rate Limit Exceeded

mn.AccountCreationModel = null;

Error: User Rate Limit Exceeded

Я боюсь, что код слишком "вовлечен" сделать демонстрацию jsFiddle.

  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded$("body")[0]Error: User Rate Limit Exceededdocument.body.

    от awj
  • Error: User Rate Limit Exceededgithub.com/SteveSanderson/knockout/issues/724

    от
  • Error: User Rate Limit Exceededko.cleanNode()Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от awj
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от awj
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceededknockmeout.net/2011/04/utility-functions-in-knockoutjs.html

    от
  • Error: User Rate Limit Exceededstackoverflow.com/questions/15063794/…)

    от
  • Error: User Rate Limit ExceededdeleteError: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit Exceeded

    от
  • Error: User Rate Limit ExceededinitError: User Rate Limit Exceeded

    от KyorCode
  • Error: User Rate Limit Exceeded

    от madcapnmckay
9 ответов
  • 9

    Error: User Rate Limit Exceeded

    <ul data-bind="template: { name: 'template', foreach: Events }"></ul>
    
    <script id="template" type="text/html">
        <li><span data-bind="text: Name"></span></li>
    </script>
    

  • 6

    Error: User Rate Limit Exceeded

    withtemplate.

  • 165

    Error: User Rate Limit Exceeded

    var element = $('#elementId')[0]; 
    ko.cleanNode(element);
    

  • 0

    Error: User Rate Limit Exceeded

    ko.applyBindings(new someModelView);ko.cleanNode($("body")[0]);ko.applyBindings(new someModelView2);

  • 30

    Error: User Rate Limit Exceeded

    ko.unapplyBindingsko.cleanNode

    ko.unapplyBindings = function ($node, remove) {
        // unbind events
        $node.find("*").each(function () {
            $(this).unbind();
        });
    
        // Remove KO subscriptions and references
        if (remove) {
            ko.removeNode($node[0]);
        } else {
            ko.cleanNode($node[0]);
        }
    };
    

  • 1

    Error: User Rate Limit Exceeded

    try {
        ko.applyBindings(PersonListViewModel);
    }
    catch (err) {
        console.log(err.message);
    }
    

        var alreadyBound = ko.utils.domData.get(node, boundElementDomDataKey);
        if (!sourceBindings) {
            if (alreadyBound) {
                throw Error("You cannot apply bindings multiple times to the same element.");
            }
            ko.utils.domData.set(node, boundElementDomDataKey, true);
        }
    

  • 4

    Error: User Rate Limit Exceeded

    .resetAll()

    var myLiveData = ko.observableArray();
    

    myLiveDatako.oberservableArray

    myLiveData$.getJSON

    $.getJSON("http://foo.bar/data.json?callback=?", function(data) {
        myLiveData.removeAll();
        /* parse the JSON data however you want, get it into myLiveData, as below */
        myLiveData.push(data[0].foo);
        myLiveData.push(data[4].bar);
    });
    

    function MyViewModel() {
        var self = this;
        self.myData = myLiveData;
    };
    ko.applyBindings(new MyViewModel());
    

    myData

    $.getJSONsetIntervalmyLiveData.removeAll();

  • 12

    Error: User Rate Limit Exceeded

    var actualCartItemsModel = { CartItems: [
      { ItemName: "FirstItem", Price: 12 }, 
      { ItemName: "SecondItem", Price: 10 }
    ] }
    

    Define bindings in html. Separate the cartItemsViewModel binding.

      
        <div data-bind="with: cartItemsViewModel">
          <div data-bind="foreach: CartItems">
            <span data-bind="text: ItemName"></span>
            <span data-bind="text: Price"></span>
          </div>
        </div>
      
    

    The store model comes from your server (or is created in any other way).

    var storeViewModel = ko.mapping.fromJS(modelFromServer)

    Define empty models on your top level view model. Then a structure of that model can be updated with actual data.

      
        storeViewModel.cartItemsViewModel = ko.observable();
        storeViewModel.cartViewModel = ko.observable();
     
    

    Bind the top level view model.

    ko.applyBindings(storeViewModel);

    When the cartItemsViewModel object is available then assign it to the previously defined placeholder.

    storeViewModel.cartItemsViewModel(actualCartItemsModel);

    If you would like to clear the cart items: storeViewModel.cartItemsViewModel(null);

  • 2

    Error: User Rate Limit Exceeded

    ko.cleanNode(element);ko.removeNode(element);