gpt4 book ai didi

javascript - Materialise CSS Collapsible 不展开

转载 作者:数据小太阳 更新时间:2023-10-29 05:17:58 24 4
gpt4 key购买 nike

我正在尝试向我的项目添加具有默认行为的可折叠 Accordion 样式。页眉似乎进入了 UI,但它不会展开以显示可折叠主体部分。任何人都知道我怎样才能使这项工作?或者看看为什么不是?

这是我的 html:

<div class="section">
<div ng-repeat="diary in diaries | orderBy:'date' ">
<div class="row">
<div class="col s2 push-s11">
<a class="btn-floating btn-large waves-effect waves-light red right-align" ng-click="deleteDiary(diary.id)"><i class="material-icons">delete_forever</i></a>
</div>
</div>
<div class="row">
<h5 class="center-align"><b>{{diary.category}}</b></h5>
<h6 class="center-align">{{diary.date}}</h6>
</div>

<div class="row">
<div class="foodContainer">
</div>
<div class="row center-align">
<ul class="collapsible popout" data-collapsible="accordion" watch>
<li ng-repeat="food in diary.foods">
<div class="collapsible-header">{{food.title}}</div>
<div class="collapsible-body">
<label><b>Calories: </b><p>{{food.calories}}</p></label>
<label><b>Fat: </b><p>{{food.fat}}</p></label>
<label><b>Protein: </b><p>{{food.protein}}</p></label>
<label><b>Sodium: </b><p>{{food.sodium}}</p></label>
<label><b>Sugars: </b><p>{{food.sugars}}</p></label>
</div>
</li>
</ul>
</div>
</div>
</div>
</div>

这是我初始化可折叠的 Controller :

"use strict";

app.controller("DiaryCtrl", function($scope, $rootScope, $location, DiaryFactory, FoodFactory){
$scope.selectedDiary = '';
// $scope.selectedDiary = 'Diary0';
$scope.totalCalories = 0;
$scope.totalFat = 0;
$scope.totalProtein = 0;
$scope.totalSodium = 0;
$scope.totalSugars = 0;
$scope.diaries = [];
$scope.foods = [];

//activate materialize collapsible list
$('.collapsible').collapsible();

//getMeals
//lists all meals on the diary page
let getAllDiaries = function(){
DiaryFactory.getDiary($rootScope.user.uid).then(function(FbDiaries) {
$scope.diaries = FbDiaries;
console.log('diaries: ', $scope.diaries);
FoodFactory.getFoodsFB($rootScope.user.uid).then(function(FbFoods){
console.log('foods from controller', FbFoods);
FbFoods.forEach(function(food){
$scope.diaries.forEach(function(diary){
// console.log('foods', food);
if(food.mealId === diary.id){
diary.foods = diary.foods || [];
diary.foods.push(food);
console.log('foods array on diary', diary.foods);
}
});
});
});
});
};
getAllDiaries();

截图如下: Screen Shot

最佳答案

我之前在使用 React.js 和 Materialize CSS 时遇到过同样的问题。

原因正如@DennyHio所说,那些DOM是不可折叠的,因为它们是在Materialize CSS完成初始化脚本后由Angular/React创建的。

我们必须手动“初始化”那些 DOM:

function afterAngularOrReactHasCreatedAllDOM (){
// Manually make all DOM with .collapsible collapsible
$('.collapsible').collapsible();
}

关于javascript - Materialise CSS Collapsible 不展开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41155058/

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