在打字稿中创建类数组

时间:2019-11-21 12:27:08

标签: c# angular typescript

如何创建类数组,然后在其中推送一些类,我只需要创建与之相同的

在C#中

 public class CheckBoxListItem
{        
    public string DisplayName { get; set; }
    public string Value { get; set; }
    public bool IsChecked { get; set; }         
}

List<CheckBoxListItem> cbx = new List<CheckBoxListItem>();
cbx.Add(new CheckBoxListItem(){DisplayName ="ABC",Value="NOW",IsChecked=true});

在打字稿中

class Graph{
graphType:string;
checkedItems:CheckBoxListItem[];
}


 class CheckBoxListItem
 {
  DisplayName: string  
  Value:string  
  IsChecked:boolean
 }

属性

  checksGraph :CheckBoxListItem;
  graphModel:Graph;

构造函数

constructor(private el:ElementRef, private renderer:Renderer) { 


  this.checksGraph = new CheckBoxListItem();
  this.graphModel = new Graph();
}

问题

  pushItem(){

    this.checksGraph.DisplayName=displayName;
    this.checksGraph.Value=value;
    this.checksGraph.IsChecked=check;      
    this.graphModel.checkedItems.push(this.checksGraph); 
 }

此行无法运行,因为checkedItems未定义

  

this.graphModel.checkedItems.push(this.checksGraph);

也不能使用

  

this.graphModel.checkedItems =新的CheckBoxListItem [50];

这将引发TypeError:CheckBoxListItem [50]不是构造函数。

1 个答案:

答案 0 :(得分:1)

在您的public async Task SomeFancyMethod(int i) { doCPUBoundWork(i); await doIOBoundWork(i); } //Main thread List<Task> someFancyTaskList = new List<Task>(); for (int i = 0; i< 10; i++) someFancyTaskList.Add(SomeFancyMethod(i)); // Do various other things here -- // how are the items handled in the meantime? await Task.WhenAll(someFancyTaskList); 类定义中,更改

Graph

checkedItems:CheckBoxListItem[];