2012-01-29 8 views
5

tengo los siguientes puntos de vista:Casilla sigue sin control después de activarse el evento

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

y tengo la siguiente plantilla para DmnItem Vista:

<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 escuchar haciendo clic en el elemento con el "GetDomain " clase. Este elemento es la casilla de verificación. Hago clic en esta casilla de verificación. Y después de llamar al métodoBasket() en ambas vistas, veo casilla de verificación sin marcar. ¿Por qué sucedió eso?

Respuesta

5

El error estaba en la representación. Después de establecer un nuevo valor en el atributo de modelo, se llamó a la función de vista y "redibujó" la casilla de verificación (por lo tanto, es quizás un error de la red troncal; después de volver a generar, el estado de la casilla de verificación no se guarda). Así que agregué una línea corta a la plantilla, que agrega el atributo "marcado" para la casilla si es necesario.

+0

crea muchos problemas :( –

0

Tal vez algo esté mal en la función toBasket (u otro). El script puede detenerse antes de llegar al final de su controlador.

Cuestiones relacionadas