gpt4 book ai didi

javascript - 使用 angularJS 从本地存储过滤数据

转载 作者:行者123 更新时间:2023-11-28 03:44:19 25 4
gpt4 key购买 nike

我似乎无法使用 AngularJS 和本地存储让过滤器为我的项目工作。没有错误,但是当我在输入字段中输入单词时,没有任何反应。有人愿意帮助我吗? :)

html:

<div ng-app="myApp" ng-controller="ViewSummaryCtrl">
<input type="text" ng-model="query">
</div>
<div class="flex-container" ng-repeat="expense in expenses | filter: {$:query}">
<div style="flex-grow: 2" class="date-col">{{expense.date}} </div>
<div style="flex-grow: 2" class="category-col">{{expense.category}} </div>
<div style="flex-grow: 3" class="description-col"> {{expense.description}}</div>
<div style="flex-grow: 2" class="amount-col">{{expense.amount| currency: "kr"}} </div>
<div style="flex-grow: 1" class="button-col">
<button class="button" type="button" ng-click="edit()">Edit</a>

controller.js

.controller('ViewSummaryCtrl', ['$scope', 'expService', 'categoryList',
function ($scope, expService, categoryList) {
$scope.expenses = expService.getExpense();

Services.js

//this function shows the expenses stored in localStorage
getExpense: function () {
expenses = [];
var prefixLength = prefix.length;
Object.keys(localStorage)
.forEach(function (key) {
if (key.substring(0, prefixLength) == prefix) {
//iterate through each item in localStorage and match it to the prefix key
var item = window.localStorage[key];
//convert stringified data back into JSON format
item = JSON.parse(item);
item.key = key;
expenses.push(item);
}
});
console.log(expenses);
return expenses;
},

最佳答案

$scope.expenses 在 ViewSummaryCtrl 中工作,但 div.flex-container 不是 div[ng-app] 的子节点。所以没有费用

关于javascript - 使用 angularJS 从本地存储过滤数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48646237/

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