PrimeNG自动填充下拉菜单仅在第一次使用时有效

时间:2019-03-08 10:26:39

标签: angular primeng primeng-dropdowns

节点版本:8.12.0 Angular版本:7.3.4 PrimeNG版本:7.0.0

我正在使用PrimeNG的自动完成组件的下拉功能。它只是第一次加载下拉列表,同样的,在单词结束后什么也没发生,这是自动完成功能的问题。我的代码如下:

    // Dom7
    var $ = Dom7;

    // Theme
    var theme = 'auto';
    if (document.location.search.indexOf('theme=') >= 0) {
    theme = document.location.search.split('theme=')[1].split('&')[0];
    }

    // Init App
    var app = new Framework7({
    id: 'io.framework7.testapp',
    root: '#app',
    theme: theme,
    on:{
    pageInit : function(page){
       console.log("page init function called aakash");
       document.addEventListener("backbutton", app.methods.onBackKeyDown, 
    false);
    }
     },
    pushState:true,
    data: function () {
    return {
      user: {
        firstName: 'John',
        lastName: 'Doe',
      },
    };
    },
   methods: {
     helloWorld: function () {
      console.log('dfvdfv')
      app.dialog.alert('Hello World!');
     },
     onDeviceReady: function() {


     },

    onBackKeyDown: function() {

       console.log("back button pressed");


      }
   },
    routes: routes,
    vi: {
      placementId: 'pltd4o7ibb9rc653x14',
     },

});

我的app.module.ts看起来像:

<p-autoComplete [(ngModel)]="selectedCompany"  styleClass="smlldropdwn" [suggestions]="companySuggestions" (completeMethod)="searchCompanies($event)" field="Name" 
                                       (onSelect)="getTagsList()" minLength ="0" [dropdown]="true" (onDropdownClick)="dropCompanies($event)" [size]="20"  spellcheck="false"> 
                                           <ng-template let-selectedCompany pTemplate="item">
                                               <div>
                                                   <div style=" text-transform: capitalize;">{{selectedCompany.Name}}</div>
                                               </div>
                                           </ng-template>
                                       </p-autoComplete>



public ManagementCompanies = [];
  public companySuggestions = [];
  searchCompanies(event) {
    if(event.originalEvent.type != "click")
    {
      if(event.query == "" || event.query == null){
          setTimeout(() => {
           this.companySuggestions = this.ManagementCompanies;
        }, 100);
      }else{
       var suggestions= [];
        this.companySuggestions = [];
        for (var i=0; i < this.ManagementCompanies.length; i++) {
          if (this.ManagementCompanies[i].Name.toLowerCase().indexOf(event.query.toLowerCase()) !== -1){
              suggestions.push(this.ManagementCompanies[i]);
          }
      }    
      this.companySuggestions = suggestions;

      }
    }     
  }

  dropCompanies(event) {
    if(event.originalEvent.type == "click")
    {
      var suggestions= [];
      var companySuggestions = [];
      suggestions = this.ManagementCompanies;
     setTimeout(() => {
        this.companySuggestions = suggestions;
      }, 100);
    }
  }

1 个答案:

答案 0 :(得分:0)

不确定代码的问题在哪里。我刚刚尝试实现primeNG autocompelete组件,并且可以正常工作。检查stackblitz链接