gpt4 book ai didi

javascript - 如何格式化 Angular 下拉菜单?

转载 作者:行者123 更新时间:2023-11-28 05:11:15 24 4
gpt4 key购买 nike

我想更改 Angular 下拉列表的格式。下拉列表用于根据 ng-model 和 customerFilter 函数过滤匹配列表。这是我目前拥有的:

HTML

<div class="drop-toggle w-dropdown-toggle">
<select ng-model="filterVariable" ng-change= "customFilter(filterVariable, allMatches)" ng-options="XXX for XXX in categories">
<option value="">By Categories</option>
</select>
</div>

我想将此过滤器的功能及其所有 CSS 带入以下格式,但我不知道如何将 ng-model、ng-change 和 ng-options 连接到它。

  <div class="sort-drop w-dropdown" data-delay="0">
<div class="drop-toggle w-dropdown-toggle">
<div class="sort-label">By Category</div>
<div class="sort-icon w-icon-dropdown-toggle"></div>
</div>
<nav class="category-dropdown w-dropdown-list">
<a class="category-link w-dropdown-link" href="#">Link 1</a>
<a class="category-link w-dropdown-link" href="#">Link 2</a>
<a class="category-link w-dropdown-link" href="#">Link 3</a>
</nav>
</div>


<div class="flex-offer-content-div" ng-repeat="match in Matches">
<div class="re-image-div w-clearfix">
<img class="rebate-image" src="{{match.offerDisplay}}" width="160">
</div>
</div>

JS

$scope.categories = ["Men", "Women", "Children"];

$scope.Matches = [{id: 1, offerDisplay: "Men"}, {id: 2, offerDisplay: "Women"}, {id: 3, offerDisplay: "Women"}];

$scope.filterVariable = ""

$scope.customFilter = function (cat, allMatches) {
if(cat === null){
$scope.Matches = allMatches;
} else {
$scope.Matches = _.compact(_.map(allMatches, function(n){
if(n.offerDisplay == cat)){
return n;
} else {
return;
}
}))
return $scope.Matches;
}
};

最佳答案

请在说“格式”时具体说明。

希望对你有帮助 How to format text in options for select in AngularJS?

关于javascript - 如何格式化 Angular 下拉菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39541287/

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