js函数的代码是:
//Set the index of theater array
$scope.setTheaterValue = function(name) {
var index = $scope.path.map(function(s){return s.name}).indexOf(name);
$scope.path = $scope.path[index].theater;
}
html代码是这样的:
<div layout-gt-sm="row" ng-init="init()">
<md-autocomplete flex="" md-input-name="autocompleteField" md-input-minlength="2" md-selected-item="geoVal" ng-model="geoVal" md-selected-item-change="setTheaterValue(item.name,theater)" md-autofocus md-autocomplete-snap md-require-match="true" md-search-text="searchText" md-items="item in querySearch(searchText)" md-item-text="item.name" md-autoselect="true" md-select-on-match="true" md-no-cache="true" md-floating-label="Select geo">
<md-item-template>
<span>{{item.name}}</span>
</md-item-template>
</md-autocomplete>
</md-input-container>
</div>
如何将该影院作为对象传递,以便我可以动态地改变路径。 谢谢你的帮助。
答案 0 :(得分:0)
如下更改控制器功能。这将允许您控制器功能与名称
一起接收剧院 $scope.setTheaterValue = function(name, theater) {
$scope.path = theater;
}
然后你需要在html中传递 item.theater 而不是剧场
<div layout-gt-sm="row" ng-init="init()">
<md-autocomplete flex="" md-input-name="autocompleteField" md-input-minlength="2" md-selected-item="geoVal" ng-model="geoVal"
md-selected-item-change="setTheaterValue(item.name,item.theater)" md-autofocus md-autocomplete-snap md-require-match="true" md-search-text="searchText" md-items="item in querySearch(searchText)" md-item-text="item.name" md-autoselect="true" md-select-on-match="true" md-no-cache="true" md-floating-label="Select geo">
<md-item-template>
<span>{{item.name}}</span>
</md-item-template>
</md-autocomplete>
</md-input-container>
</div>