【问题标题】:Autocomplete friend list on social engine is not working properly社交引擎上的自动完成好友列表无法正常工作
【发布时间】:2018-01-31 15:03:09
【问题描述】:

我正在为 SocialEngine 网站开发建议功能。我在文本框上编写了以下代码,以根据插入的文本提供建议。但是没有为控制器返回的所有结果调用注入方法。它正在跳过其中一些。我希望它为每个结果调用一次。这是代码 -

new Autocompleter.Request.JSON('global_search_field', '<?php echo $this->url(array('module' => 'user', 'controller' => 'public', 'action' => 'suggest','message' => true), 'default', false) ?>', {          
        'minLength': 1,
        'delay' : 50,
        'className': 'message-autosuggest',
        'injectChoice': function(token){
             console.log("called");
          if(token.type == 'user'){
            console.log("User");
            var choice = new Element('li', {
              'class': 'autocompleter-choices',
              'id':token.guid
            });
            new Element('div', {
              'html': '<a id="'+token.id+'" href="'+token.url+'">'+token.photo+this.markQueryValue(token.label)+'</a>',
              'class': 'autocompleter-choice'
            }).inject(choice);
          }
          else {
              console.log("Heading");
            var choice = new Element('li', {
              'class': 'autocompleter-choices',
              'id':token.guid
            });

            new Element('div', {
                'html': '<a class="menu-heading" style="margin:-9px;" id="'+token.id+'" >'+this.markQueryValue(token.id)+'</a>',
                'class': 'autocompleter-choice'
            }).inject(choice);
          }
          this.addChoiceEvents(choice).inject(this.choices);
            choice.store('autocompleteChoice', token);     
        },
        'onPush' : function(){
         if( $('toValues').value.split(',').length >= maxRecipients ){
            $('to').disabled = true;
          }
        }
    });

我已经检查了从控制器返回的数据,它返回了多个结果,但是有些注入器只被调用以获得更少的结果。

更新 - 仅从控制器返回的前 10 个值调用注入器方法

【问题讨论】:

    标签: javascript php json socialengine


    【解决方案1】:

    您正在使用Autocompleter 类的实例。你可以在/externals/autocompleter/Autocompleter.js找到它的源代码。注意maxChoices: 10 变量。您会注意到它限制了代码中以下操作的数量。您需要做的就是将此变量的值覆盖为您需要的任何值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-16
      • 2014-05-18
      • 2020-10-12
      • 2018-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多