Create string array of textarea using n as separator

Asked

Viewed 194 times

-3

How to create a string array using line break as separator value.split("\n")?

Ex:

<textarea placeholder="LISTA" type="text"> </textarea>

And how can I send a request using Axios for each line break using a foreach?

Failed attempt:

            <div id="app">
            <div v-for="item in list" :key="item.id">
              <b-form-textarea v-model="item.value"></b-form-textarea>
              <br/>
            </div>
          </div>
<script>
new Vue({
        return this.list.map(e => {
        return axios.get('http://localhost/fg/nova.php?lista='+e.value.split("\n"))
        .then(function (response) {
          // handle success
          console.log(response);
        })
    });
})
</script>
  • split and a for/foreach does not result, so make the ajax call inside the loop

  • Wagner, I believe your question is not about you, try to create lean examples without what is not part of the problem, it helps who wants to help you, okay?

1 answer

0

Already answered your own question: use the split to separate lines. What was missing from your code was to iterate over the array, with for or foreach to, as you asked, make a call ajax for each row, or each item in the array:

document.getElementById("testar").addEventListener("click", teste);

function teste() {
  // usarei isso para que "e" seja o textarea
  var e = document.getElementById("lista");
  var lista = e.value.split("\n");

  lista.forEach(function(linha){ 
      console.log(linha);
      // então é só fazer a chamada ajax:
      // axios.get('http://localhost/fg/nova.php?lista=' + linha) ....
  });

}
<textarea id="lista" placeholder="LISTA" type="text"> </textarea>
<button id="testar">Testar</button>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.