【问题标题】:Angucomplete Alt url remoteAngucomplete Alt url 远程
【发布时间】:2016-09-13 11:04:54
【问题描述】:

我使用 Angucomplete Alt 指令进行自动完成。 到目前为止它工作正常,但我想向我的服务器发出特定请求。 /search/users/name?s=

<div angucomplete-alt
             id="input-name"
             placeholder="Name"
             pause="50"
             search-fields="name"
             remote-url=/users/name?s=
             title-field="name"
             minlength="3"
             match-class="angucomplete-match">
        </div>

换句话说,我想在将请求发送到我的服务器之前将所有空格更改为点。

提前谢谢你!

【问题讨论】:

    标签: javascript angularjs html angularjs-directive


    【解决方案1】:

    您可以使用 remote-api-handle 选项在字符串发送到服务器之前对其进行修改。

    <div angucomplete-alt
             id="input-name"
             placeholder="Name"
             pause="50"
             search-fields="name"
             remote-url-handler="searchAPI"
             title-field="name"
             minlength="3"
             match-class="angucomplete-match">
        </div>
    

    在您的控制器中:

    $scope.searchAPI = function(userInputString, timeoutPromise) {
      //Modify input before it gets sent to the server
      userInputString = userInputString.replace(' ', '.');
      return $http.post('/users/name', {s: userInputString}, {timeout: timeoutPromise});
    }
    

    【讨论】:

      【解决方案2】:

      使用远程 API 处理程序:

      <angucomplete-alt
                   id="input-name"
                   placeholder="Name"
                   pause="50"
                   search-fields="name"
                   remote-api-handler="searchAPI"
                   title-field="name"
                   minlength="3"
                   match-class="angucomplete-match" />
      

      【讨论】:

        猜你喜欢
        • 2015-01-03
        • 2015-11-21
        • 1970-01-01
        • 2015-03-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-05
        • 1970-01-01
        相关资源
        最近更新 更多