gpt4 book ai didi

javascript - 如何在 angularjs 中进行自动完成(过滤器列表不显示)

转载 作者:行者123 更新时间:2023-11-30 16:55:36 25 4
gpt4 key购买 nike

我正在尝试在 angular js 中进行自动完成。但是当我在文本字段中键入任何内容时,它不会反射(reflect)在 View 中换句话说,它在文本字段中键入后不提供过滤器列表。我有站名和站代码。我需要用过滤器代码过滤我的列表。这是我的代码

http://codepen.io/anon/pen/xGxKKE

当我键入“B”时,它应该显示站代码从“B”开始的列表。你能告诉我哪里做错了吗?

<ion-content>
<div class="list">
<label class="item item-input">
<span class="input-label">StationName</span>
<input type="text" ng-model="station.stationCode" class="bdr">
</label>
</div>
<div class="list">
<li class="item" ng-repeat="station in data.data">{{station.stationName+"-("+station.stationCode+")"}}</li>
</div>
</ion-content>

最佳答案

您实际上并没有过滤列表:

http://codepen.io/anon/pen/rVNBOO

添加:

 $scope.startsWith = function (actual, expected) {
var lowerStr = (actual + "").toLowerCase();
return lowerStr.indexOf(expected.toLowerCase()) === 0;
};

并更改了 ng-repeat:

ng-repeat="station in data.data | filter:station.stationCode:startsWith"

编辑:

startsWith 中的代码采用实际值(在您的情况下为 stationName)并检查它是否在字符串的开头找到搜索到的字符。如果 indexOf "your searched string"为 === 0 - 则字符串以这些字符开头。

关于javascript - 如何在 angularjs 中进行自动完成(过滤器列表不显示),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29769188/

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