Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

angular - Sending data with a drop-down list

I had a problem for a while I have a function rest with spring boot that save for each vehicle documents

the rest is consumed with angular

//Spring boot 
    @PostMapping("/document_vehicule")
    public void Document_vehicule(@RequestParam(name = "id_vehicule") int id_vehicule,
            @RequestParam(name = "id_document") int id_document) {

        Document document = this.documentRepository.findById(id_document).orElse(null);
        Vehicule vehicule = this.vehiculeRepository.findById(id_vehicule).orElse(null);

        vehicule.getDocuments().add(document);
        document.getVehicules().add(vehicule);

        this.vehiculeRepository.save(vehicule);
        this.documentRepository.save(document);

    }
//Angular

//add in the drop-down list the documents selected by vehicle
ajouteDocumentVehicule(event, index1) {
    let index = this.DocumentVehicule.indexOf(
      index1 + '.' + event.target.value
    );

    if (index == -1 && event.target.checked == true) {
      this.DocumentVehicule.push(index1 + '.' + event.target.value);
    } else {
      this.DocumentVehicule.splice(index, 1);
    }
    console.log(this.DocumentVehicule);
  }


  //implemente(the function rest)
  document_vehicule() {
    let DocumentVehicule1 = []; 
    //implemente(Document_vehicule)
    this.updatecompagnie_fiche.forEach((element, index) => {
      this.DocumentVehicule.forEach((element1) => {
        if (index == element1.split('.')[0])
          DocumentVehicule1.push({
            id_vehicule: element.id_vehicule,
            document: element1.split('.')[1],
          });
      });
    });

     DocumentVehicule1.forEach((element) => {
      this.auth
        .Document_vehicule(element.id_vehicule, element.document)
        .subscribe();
     });

    this.tabledocument_vehicule.push('aksam');
  }

my problem when I click on the button it sends me doubling data for example: id_vehicule :91 id_document :10 id_vehicule :91 id_document :10.

I solved this problem by adding a primary key for the two foreign keys but I find that another problem, duplicate data is not added. The problem is in the function because I have already tested on the function without sending by the post method it sends the data correctly. noted that: I have a drop-down list that is displayed next to each vehicle.

Thank you for your help


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...