Angularjs推进搜索

时间:2018-01-29 08:28:19

标签: php angularjs angularjs-directive angular2-directives search-box

UI

我拥有上述用户界面,当我输入网站名称时,它将显示指定我搜索的名称的网站的所有名称,我可以选择我想要的名称并将值设置为文本之后我想通过单击按钮从数据库中获取特定siteid到另一个文本框     

网站A /名称

<input type='text' ng-keyup='fetchUsers()' ng-model='searchText' 
placeholder='Search Site by name'><br>
<ul id='searchResult' >
         <li ng-click='setValue($index)' ng-repeat="result in searchResult" >{{result.sitename}}</li>
</ul>

控制器

app.controller('fetchCtrl', ['$scope', '$http', function ($scope, $http) {

// Fetch data
$scope.fetchUsers = function () {

    $http({
        method: 'post',
        url: 'getData.php',
        data: { searchText: $scope.searchText }
    }).then(function successCallback(response) {
        $scope.searchResult = response.data;

    });

}

// Set value to search box
$scope.setValue = function (index) {
    $scope.searchText = $scope.searchResult[index].sitename;
    $scope.searchResult = {};

    include 'config.php';

    $data = json_decode(file_get_contents("php://input"));

    $search = $data ->searchText;

    $sel = mysqli_query($con, "select sitename from site where sitename like '%".$search."%' limit 5");

    $data = array();
    $data = array();
    while ($row = mysqli_fetch_array($sel)) {
        $data[] = array("sitename"=>$row['sitename']);
    }

    echo json_encode($data);
}
}])    

因为我对angularjs有非常基本的了解,所以请帮助我

0 个答案:

没有答案