Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用angular 4将一个数组列表中的项组合插入另一个数组列表_Javascript_Angular_Typescript_Arraylist_Angular2 Forms - Fatal编程技术网

Javascript 使用angular 4将一个数组列表中的项组合插入另一个数组列表

Javascript 使用angular 4将一个数组列表中的项组合插入另一个数组列表,javascript,angular,typescript,arraylist,angular2-forms,Javascript,Angular,Typescript,Arraylist,Angular2 Forms,我有一个arrayList(selectedSources),其中包含以下项目: this.selectedSources.push( { id: 0, text: "A" }, { id: 1, text: "B" }, { id: 2, text: "C" }, { id: 3, text: "D"} ); 用户可以选择任何或所有这些项目。当用户选择项时,我需要将这些项的组合动态移动到另一个数组列表中 目前,我正在使用if/else语句来执行此操作。有没有一种方法可以动态

我有一个arrayList(selectedSources),其中包含以下项目:

this.selectedSources.push(
  { id: 0, text: "A" },
  { id: 1, text: "B" },
  { id: 2, text: "C" },
  { id: 3, text: "D"}
); 
用户可以选择任何或所有这些项目。当用户选择项时,我需要将这些项的组合动态移动到另一个数组列表中

目前,我正在使用
if/else
语句来执行此操作。有没有一种方法可以动态地做到这一点

下面是我的代码:

  if (
    this.selectedSources.some(x => x.Value === "B") &&
    this.selectedSources.some(x => x.Value === "C")
  ) {
    if (this.formulalist != undefined) {
      //this.formulalist.length = 0;
      this.formulalist = [];
    }
    this.formulalist.push({
      Value: "B - C",
      Name: "B - C",
      IsVisible: true,
      UpdateFlag: "A",
      Market: "",
      FormulaType: "diff",
      FormulaSet1: "1",
      FormulaSet2: "3",
      checked: null
    });
    this.formulalist.push({
      Value: "% B - C",
      Name: "% B - C",
      IsVisible: true,
      UpdateFlag: "A",
      Market: "",
      FormulaType: "percent",
      FormulaSet1: "1",
      FormulaSet2: "3",
      checked: null
    });
   else if (
    this.selectedSources.some(x => x.Value === "B") &&
    this.selectedSources.some(x => x.Value === "D")
  ) {
    if (this.formulalist != undefined) {
      //this.formulalist.length = 0;
      this.formulalist = [];
    }
    this.formulalist.push({
      Value: "B - D",
      Name: "B - D",
      IsVisible: true,
      UpdateFlag: "A",
      Market: "",
      FormulaType: "percent",
      FormulaSet1: "1",
      FormulaSet2: "4",
      checked: null
    });
    this.formulalist.push({
      Value: "% B - D",
      Name: "% B - D",
      IsVisible: true,
      UpdateFlag: "A",
      Market: "",
      FormulaType: "percent",
      FormulaSet1: "1",
      FormulaSet2: "4",
      checked: null
    });
    ............
    ............
如果用户选择B和C,那么我需要推送这些项目的组合。例如:
(B-C)
%B-C

我们如何在不使用硬编码值,而是使用angular 4中的用户选择的情况下动态执行此操作

selectedSources
具有用户选择的列表

如果用户选择
B,A,C
我需要将这些项目推送到另一个数组列表中
A-C、%A-C、A-B、%A-B、B-C、%B-C

我在这里为大家举了一个例子,希望它能有所帮助:

如图所示,有4个复选框


结果是:

我在UI中使用复选框,然后单击add按钮以推到另一个数组列表
用户必须从列表1中选择2项complicated@FerhadOthman我有我在problemPlease中提到的场景,请解释我的示例中的错误是什么?看到了吗update@FerhadOthman我不知道是谁否决了你。。谢谢你的帮助,我会努力学习你的例子。。。