3

当用户在自动完成框中键入电影名称时,我正在使用此代码搜索电影。我在控制台上得到结果,但没有显示项目文本 Html

<md-autocomplete md-selected-item="selectedMovie"
    md-search-text-change="searchMovie(searchText)"
    md-search-text="searchText"
    md-selected-item-change="selectedItemChange(movie)"
    md-items="movie in movies"
    md-item-text="movie.title"
    md-min-length="1" 
    placeholder="Search Movies">
  <md-item-template>
        <span md-highlight-text="searchText" md-highlight-flags="^i"> 
          {{movie.title}}
        </span>
    </md-item-template>
    <md-not-found>
        No Movies matching were found.

    </md-not-found>
</md-autocomplete>

JS

 $scope.searchMovie = function (text) {
            $http.get('api/movie', {
                params: {
                    searchMovieName: text
                }
            }).success(function (data, status) {
                console.log(data.results);
                console.log(status);
                $scope.movies = data.results;
            }).error(function (err) {
                console.log(err);
            });
        };
4

1 回答 1

2

JS

$scope.searchMovie = function(text) {
  return $http.get('api/movie', {
    params: {
      searchMovieName: text
    }
  });
}

在你的 html 中

<md-autocomplete md-selected-item="selectedMovie"
 md-search-text="searchText"
 md-selected-item-change="selectedItemChange(movie)"
 md-items="movie in searchMovie(searchText)"
 md-item-text="movie.title"
 md-min-length="1" 
 placeholder="Search Movies">
  <md-item-template>
    <span md-highlight-text="searchText" md-highlight-flags="^i"> 
      {{movie.title}}
    </span>
  </md-item-template>
  <md-not-found>
    No Movies matching were found.
  </md-not-found>

$http.get 是返回可以在 md-items 中使用的 promise 对象。像 md-items="movie in searchMovie(searchText)"

于 2016-05-18T12:09:38.590 回答