代码之家  ›  专栏  ›  技术社区  ›  Bhrungarajni

如何根据angular2中的当前用户ID筛选数据集

  •  1
  • Bhrungarajni  · 技术社区  · 6 年前

    我有一组数据,因为我必须用我的userId过滤数据,并且只显示列表中的数据。 请帮忙。 TS码:

    getDicomList() {
        this.service.getDicomList(params)
          .subscribe((res) => {
            this.dicomLists = res.Body.Data.dicomList;
            console.log(this.dicomLists, "shghds")
            let ids = this.dicomLists.map(item => item.CreatedBy);
           let filteredData = this.dicomLists.filter(item => ids.indexOf(item.CreatedBy) === -1);
          })
    
          i need to compare with my this.userId and item.CreatedBy
    

    慰问:

    (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
    0: {StudyInstanceUID: "999.999.1.19941016.83000", StudyID: "ACC99", SeriesNumber: "2", AcquisitionNumber: "0", InstanceNumber: "101", …}
    1: {StudyInstanceUID: "1.3.6.1.4.1.18047.1.11.10021841473447061672", StudyID: "", SeriesNumber: "3", AcquisitionNumber: "1", InstanceNumber: "49", …}
    2: {StudyInstanceUID: "1.3.6.1.4.1.18047.1.11.10021841473447061672", StudyID: "", SeriesNumber: "3", AcquisitionNumber: "1", InstanceNumber: "49", …}
    3: {StudyInstanceUID: "1.2.840.113619.2.55.3.604637917.369.1487635615.91", StudyID: "35112", SeriesNumber: "7", AcquisitionNumber: "1", InstanceNumber: "3", …}
    4: {StudyInstanceUID: "1.3.6.1.4.1.18047.1.11.10021841473447061672", StudyID: "", SeriesNumber: "3", AcquisitionNumber: "1", InstanceNumber: "49", …}
    5: {StudyInstanceUID: "1.2.840.113619.2.55.3.604637917.369.1487635615.91", StudyID: "35112", SeriesNumber: "7", AcquisitionNumber: "1", InstanceNumber: "5", …}
    6: {StudyInstanceUID: "1.2.840.113619.2.55.3.604637917.369.1487635615.91", StudyID: "35112", SeriesNumber: "7", AcquisitionNumber: "1", InstanceNumber: "1", …}
    7: {StudyInstanceUID: "1.2.840.113619.2.55.3.604637917.369.1487635615.91", StudyID: "35112", SeriesNumber: "7", AcquisitionNumber: "1", InstanceNumber: "4", …}
    8: {StudyInstanceUID: "1.2.840.113619.2.55.3.604637917.369.1487635615.91", StudyID: "35112", SeriesNumber: "7", AcquisitionNumber: "1", InstanceNumber: "4", …}
    9: {StudyInstanceUID: "1.3.6.1.4.1.18047.1.11.10021841473447061672", StudyID: "", SeriesNumber: "4", AcquisitionNumber: "1", InstanceNumber: "49", …}
    length: 10
    __proto__: Array(0)
    
    5 回复  |  直到 6 年前
        1
  •  2
  •   Hitesh Kansagara    6 年前

    getDicomList() {
        this.service.getDicomList(params)
          .subscribe((res) => {
            this.dicomLists = res.Body.Data.dicomList;
            console.log(this.dicomLists, "shghds")
            //let ids = this.dicomLists.map(item => item.CreatedBy);
           let filteredData = this.dicomLists.filter(item => this.userId == item.CreatedBy);
          })
    
        2
  •  2
  •   Karan Patel    6 年前

    你只需要小小的修改。

    getDicomList() {
        this.service.getDicomList(params)
          .subscribe((res) => {
            this.dicomLists = res.Body.Data.dicomList;
    
           let filteredData = this.dicomLists.filter(item => item.CreatedBy === this.userId);
          })
    
        3
  •  1
  •   zgue    6 年前

    你能试试下面的代码吗

    let filteredData = this.dicomLists.filter(item => (this.userId == item.CreatedBy));
    
        4
  •  0
  •   VizardCrawler    6 年前

    你应该总是打空支票

            getDicomList() {
            this.service.getDicomList(params)
              .subscribe((res) => {
                     this.dicomLists = [];
                     // Null check else it will throw errors
                     if(res.body && res.body.Data 
                          && res.body.Data.dicomList
                          && res.body.Data.dicomList.length){
                       this.dicomLists = res.Body.Data.dicomList;
                     }
               return this.dicomLists.filter(item => this.userId == item.CreatedBy);
              })
    
        5
  •  0
  •   H Mirindra    6 年前
    this.service.getDicomList(params)
      .subscribe((res) => {
        this.dicomLists = res.Body.Data.dicomList;
        console.log(this.dicomLists, "shghds")
        let ids = this.dicomLists.map(item => item.CreatedBy); // the map is used to filter the properties of the object if necessary
       let filteredData = this.dicomLists.filter(item => ids.indexOf(item.CreatedBy) === -1); // Filter YES but the criteria in the filter is not good
      })
    

    就这样

    this.service.getDicomList(params).subscribe((res) => {
        this.dicomLists = res.Body.Data.dicomList;
        this.dicomLists.filter(item => item.CreatedBy === this.userId);
    })