2012-01-29 10 views
5

Mam następujące widoki:CheckBox nadal zaznaczona po wyzwoleniu zdarzenia

window.DmnView = Backbone.View.extend({ 
     template: _.template($("#tmpl_dmnListItem").html()), 
     events: { 
      "click .getWhois": "showWhois", 
      "click .getDomain": "toBasket" 
     }, 
     initialize: function() { 
      this.model.bind('change', this.render, this); 
      this.model.bind('destroy', this.remove, this); 
      this.bind('toBasket', dmnListApp.toBasket, this); 
     }, 
     render: function() { 
      return $(this.el) 
        .attr("class", this.model.get("free") ? "dmnItem green" : this.model.get("checked") ? "dmnItem red" : "dmnItem red loader") 
        .html(this.template(this.model.toJSON())); 
     }, 
     remove: function() { 
      $(this.el).remove(); 
     }, 
     showWhois: function() { 
      showBoxes(this.model.get("info")); 
      return false; 
     }, 
     toBasket: function() { 
      this.model.toBasket(); 
      this.trigger('toBasket'); 
     } 
    }); 

    window.DmnListApp = Backbone.View.extend({ 
     el: $("#regWrap"), 
     events: { 
      "keypress #dmnName": "checkAll" 
     }, 
     initialize: function() { 
      this.input = this.$("#dmnName"); 
      this.list = this.$("#dmnList"); 
      this.basket = this.$("#dmnBasket"); 
      dmnList.bind('add', this.addOne, this); 
      dmnList.bind('all', this.render, this); 
     }, 
     render: function() { 

     }, 
     addOne: function(dmnItem) { 
      var view = new DmnView({model : dmnItem}); 
      this.list.append(view.render()); 
     }, 
     checkOne: function(name, zone, price, days) { 
      dmnList.create({name: name, zone: zone, price: price, days: days}); 
     }, 
     checkAll: function(e) { 
      var name = this.input.val(); 
      if (!name || e.keyCode != 13) return; 
      if (name == "") 
       name = "yandex"; 
      dmnList.destroyAll(); 
      var zoneList = dmnList.domainsInfo.Name; 
      var costList = dmnList.domainsInfo.CostOrder; 
      var daysList = dmnList.domainsInfo.DaysToProlong; 
      var parent = this; 
      $.each(zoneList, function(key, zone) { 
       parent.checkOne(name, zone, costList[key], daysList[key]); 
      }); 
      this.input.val(""); 
     }, 
     toBasket: function(){ 
      if (this.model.get("inBasket")){ 
       dmnListApp.basket.append($(this.el)); 
      }else{ 
       dmnListApp.list.append($(this.el)); 
      } 
     } 
    }); 

I mam następujący szablon dla DmnItem Widok:

<script id="tmpl_dmnListItem" type="text/template"> 
    <%= checked&&free ? "<input type='checkbox' class='getDomain' />" : ""%><%= name %>.<%= zone %> <%= (free || !checked) ? (checked) ? '<p class="fr">'+price+" руб./"+days+'</p>' : "" : "<a href='#' class='getWhois fr'>WhoIs</a>" %> 
</script> 

DmnView słuchać kliknięcie na elemencie z „getDomain " klasa. Ten element to pole wyboru. Klikam to pole wyboru. I po wywołaniu do metody Basker() w obu widokach widzę jeszcze niezaznaczone pole wyboru. Dlaczego tak się stało?

Odpowiedz

5

Błąd polegał na renderowaniu. Po ustawieniu nowej wartości do atrybutu modelu, funkcja renderowania widoku została wywołana i "odświeżona" pole wyboru (może to być błąd szkieletu - po ponownym renderowaniu stan pola wyboru nie jest zapisywany). Dodałem więc krótką linię do szablonu, który w razie potrzeby dodaje "zaznaczony" atrybut pola wyboru.

+0

tworzy wiele problemów :( –

0

Może coś jest nie tak z funkcją do koszyka (lub innego). Skrypt może zatrzymać się przed dotarciem do końca programu obsługi.

Powiązane problemy