gpt4 book ai didi

javascript - 如何计算 UI-Angular 和 Bootstrap 中的字符数

转载 作者:行者123 更新时间:2023-12-03 09:04:27 25 4
gpt4 key购买 nike

我有一个使用 Angular 和 Angular UI 构建的应用程序。我正在尝试计算多个 Accordion 中的字符,如 plunker 中所示。我的代码只返回前两个字符,然后什么都没有?

我做错了什么吗?

密码是:Example code

app.js

$scope.what=[];
$scope.why=[];

Object.defineProperty($scope, 'characters', {
get() {
return $scope.what.length + $scope.why.length;
}
});

HTML:

{{characters}} 

但就像我说的,这只返回前两个字符?

最佳答案

为什么以及什么是数组,如果你想计算这些数组中的所有字符,请尝试:

Object.defineProperty($scope, 'characters', {
get() {
return $scope.what.join('').length + $scope.why.join('').length;
}
});

关于javascript - 如何计算 UI-Angular 和 Bootstrap 中的字符数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32222550/

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