如何将选定的HTML表行值显示为输入文本?

时间:2018-04-01 15:59:55

标签: html angular tablerow

我有一个名为Equipment的表,我希望将行显示在另一个组件的输入文本中,任何想法plz或例子。 这是我的表型号



export class store{
    id: number;
    park_id:string;
    BonMvt:Array<string>;
    SN: string;
    reference:string;
    ModelType: string;
    State: string;
    isActived: string;
}
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

参考以下高级实现

StackBlitz网址:https://stackblitz.com/edit/angular-ylp9z4

答案 1 :(得分:1)

<强> TableWithInputComponent

 import java.util.*;

`public class Question6` {

   static void mergeSort(int arr1[], int o, int k, int x)  {
    int num1 = k - o + 1;
    int num2 = x - k;

    int temp1[] = new int [num1]; //creation of two temporary arrays to store in
    int temp2[] = new int [num2];


    for (int i=0; i<num1; ++i)   //for loops to copy the data to the temporary arrays
        temp1[i] = arr1[o + i];

    for (int j=0; j<num2; ++j)
        temp2[j] = arr1[k + o + j];





    int i = 0, j = 0; //starting position of temporary arrays


    int s = l; //starting position of the merged two temporary arrays
    while (i < num1 && j < num2)  {

        if (temp1[i] <= temp2[j])  {
            arr1[s] = temp1[i];
            i++;
        }
        else  {
            arr1[s] = temp2[j];
            j++;
        }
        s++;
    }

    //code to copy elements from temp1
    while (i < num1)
    {
        arr1[s] = temp1[i];
        i++;
        s++;
    }

   //code to copy elements from temp2
    while (j < num2)
    {
        arr1[s] = temp2[j];
        j++;
        s++;
    }
}

/
void forSorting(int arr2[], int o, int x) //main method that carries out merge sort
{
    if (o < x)
    {
        // Find the middle point
        int a = (o+x)/2;

        // Sort first and second halves
        forSorting(arr2, o, a);
        forSorting(arr2, a+1, x);

        // Merge the sorted halves
        mergeSort(arr2, o, a, x);
    }
}

public static void main(String[] args) {
    Question6 qs = new Question6();
    Scanner sc = new Scanner(System.in);
    int [] duplicate = new int[10];

    System.out.println("Please input the numbers to be checked for repetition.");

    for(int x = 0; x < 10; x++)
    {
        duplicate[x] = sc.nextInt(); //filling array
    }

    int length = duplicate.length;
    qs.forSorting(duplicate, 0, length-1); //calling method forSorting

    System.out.println(Arrays.toString(duplicate)); //displays array

    for (int count = 1; count < 10; count++)
    {
        if (duplicate[count] == duplicate[count - 1]) {
            //displays the duplicates
            System.out.println("Duplicate: " + duplicate[count]);

        }
    }
}

表格与 - input.component.html

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-table-with-input',
  templateUrl: './table-with-input.component.html',
  styleUrls: ['./table-with-input.component.css']
})

export class TableWithInputComponent implements OnInit {

  stores : store [] = [];
  constructor() { }

  ngOnInit() {
for (let i=0; i<10; i++) {
  this.stores.push(new store(i));
}
  }
  submit() {
    console.log(this.stores)
  }
}

export class store{
  id: number;
  park_id:string;
  SN: string;
  reference:string;
  ModelType: string;
  State: string;
  isActived: string;
  constructor(i: any) {
    this.id = i;
    this.park_id = 'park_id'+i;
    this.SN = 'SN'+i;
    this.reference = 'reference'+i;
    this.ModelType = 'ModelType'+i;
    this.State = 'State'+i;
    this.isActived = 'isActived'+i;
  }
}