gpt4 book ai didi

javascript - 从 uib-typeahead 自定义弹出窗口中检索 filteredItems 不起作用

转载 作者:行者123 更新时间:2023-11-30 06:17:27 25 4
gpt4 key购买 nike

通过 $scope 从 Controller 中的 ng-repeat 中检索 filteredItems 不起作用

我正在尝试从 ng-repeat 中获取过滤的项目,但是当控制台记录 $scope.filteredItems 的值时,我得到了未定义的信息。我什至尝试了 Can't get the filtered items from my filtered list inside a modal 中提供的解决方案但它也没有用。

ng-repeatuib-typeahead 中typeahead 下拉菜单的自定义弹出模板。我试图在父 Controller 中获取过滤后的值。

example-input.component.ts

/////////////////////////////////
componentController.$inject = ['$scope', 'exampleDataService'];
function componentController($scope, exampleDataService) {

var someInput = this;
someInput.typedText = '';
someInput.onKeyPress = onKeyPress;
return;

/////////////////////////////////
//controller implementation detail
/////////////////////////////////

function onKeyPress(){
console.log($scope.filteredItems); // prints undefined
}
}

用于弹出窗口的 UIB-Typeahead 自定义模板

<script type="text/ng-template" id="input-custom-template.html">
<ul class='dropdown-menu' ng-show='isOpen() && !moveInProgress'
ng-style="{top: position().top+'px', left: position().left+'px'}"
role='listbox' aria-hidden='{{!isOpen()}}' match-limit in-view-container>
<li style="max-height:0;overflow:hidden"><span in-view="$inview && matchLimit.reset()"> </span></li>
<li ng-repeat='match in (filteredItems = (matches | someMatchSort:query | limitTo:matchLimit.value)) track by some.model.example '
ng-class='{active: isActive($index) }'
ng-mouseenter='selectActive($index)'
ng-click='selectMatch($index, $event)'
role='option' id='{{::match.id}}'
in-view="!$inview && isActive($index) && scrollTarget.scrollIntoView()"
scroll-target
>
<div uib-typeahead-match index='$index' match='match'
query='query' template-url='templateUrl'>
</div>
</li>

</ul>
</script>
<input type="text" ng-model="someInput.typedText" typeahead-min-length="1"
uib-typeahead="option.example as option.value for option in someInput.options | filter:{value:$viewValue}"
class="form-control input-text-example icon-search"
placeholder="example"
typeahead-popup-template-url="input-custom-template.html"
ng-keypress="someInput.onKeyPress()"/>

如果您需要任何其他信息,请告诉我。还有一个名为 someMatchSort.filter.ts 的过滤器,但我不确定将它添加到此处是否会有所不同。无论如何让我知道,我会更新我的问题

最佳答案

您可能希望在您的案例中使用 ng-keyup。然后在你的组件中这样写

function onKeyPress(){
console.log($scope.$$childHead.matches.length);
}

关于javascript - 从 uib-typeahead 自定义弹出窗口中检索 filteredItems 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55298674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com