Add CheckBox dynamically

0

I have a project where when I click on a button, I want to pick up the text of 3% with different% and add them to a TextBox .

So far so good, the problem comes up when I want to add these% automatic%, for the user to add more rows.

Here is an example of what it will introduce into CheckBox :

CheckBoxLinhas.Text = "Quantidade: " + TextBoxQuantidade.Text + " Artigo: " + TextBoxArtigo.Text + " Valor: " + TextBoxValor.Text;

How can I then create% automatic%?

    
asked by anonymous 14.04.2016 / 14:40

1 answer

1

You could use an observable array of Knockout.js to do this.

var ViewModel = function(){
  self = this;
  //inicializa a lista de checkboxs vazia
  self.listaCheckBox = ko.observableArray([]);
  
  
  self.adicionaCheckBox = function(){
   self.listaCheckBox.push("checkbox"); 
   }
   
}

$(document).ready(function () {
        var viewModel = new ViewModel();

        ko.applyBindings(viewModel);
 });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>

<button type="button" data-bind="click:$root.adicionaCheckBox">Adicionar CheckBox</button>
	<ul   data-bind="foreach: $root.listaCheckBox()">
	  <li>
	  <input type="checkbox"/><p class="form-control-static" data-bind="text: $data"></p>
	  </li>
	</ul>
    
14.04.2016 / 15:42