【问题标题】:angucomplete undesirable click event firesangucomplete 不受欢迎的点击事件触发
【发布时间】:2018-12-15 20:30:39
【问题描述】:

最近,我正在使用 angucomplete 在我的搜索中实现自动完成,现在我希望实现的期望输出是,每当我通过单击鼠标选择自动完成建议之一时,它都会导航到所需的 url,或者说谷歌.com 用于测试目的。下面代码的问题是,当我单击文本框而不选择任何建议时,navToUrlByClick 函数将触发。自从作者刚刚开始探索 javascript 以来,对于此类问题的任何建议和抱歉。提前致谢!

这是我的 test.html 代码:

<div class="padded-row" ng-click="navToUrlByClick('http://www.google.com')">
     <div angucomplete-alt id="ex5"
       placeholder="Search projects"
       pause="50"
       selected-object="selectedProject"
       remote-url="http://localhost:5000/"
       remote-url-request-formatter="remoteUrlRequestFn"
       remote-url-data-field="items"
       title-field="subs_name"
       minlength="1"
       input-class="form-control form-control-small"
       match-class="highlight">
     </div>
</div>

这是我的 app.js 代码:

$scope.navToUrlByClick = function(str){
  if ((str != "") || (str != null))
  {
    console.log(str)
    //$window.location.href = str;
  }
}

【问题讨论】:

    标签: javascript angularjs autocomplete navigateurl


    【解决方案1】:

    我通过使用回调和下面几行代码来解决这个问题并添加到我的 app.js 中

    $scope.selectedProject = function(selected) {
      if (selected) {
        // window.alert('You have selected ' + selected.title);
        $window.location.href = "http://www.google.com";
      } else {
        console.log('cleared');
      }
    };
    

    结案!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-02
      • 1970-01-01
      • 2011-11-19
      • 1970-01-01
      • 2023-03-27
      • 2021-02-20
      • 2020-12-27
      相关资源
      最近更新 更多