gpt4 book ai didi

javascript - 如何逐行增加数字

转载 作者:行者123 更新时间:2023-12-01 03:17:28 24 4
gpt4 key购买 nike

Plunker.

我已经实现了上面的plunker,在该plunker中,rowId随着Alphabets的增加而增加。如下所示

该组件中将有 +++ 以及 - 按钮。如果我按+,那么 Rowid 将从起始字母(A)开始。如果我按 ++ 那么父 rowid + 以起始字母开头的意思是(AA)。再次,如果我按 ++ ,则父 rowId + 以起始字母开头意味着 (AAA)。这样它就会增加。

请访问Plunker here.

但我想用 Numbers 手段实现该功能

对于单个加号,它应该显示1,对于++,它应该显示111,就像我需要实现的那样。

你能帮我实现这个功能吗?

var newRow = {
"rowId": "A"
}
$scope.componentList = [];
$scope.componentList.push(angular.copy(newRow));

$scope.addParentRow = function(rowId) {
var newGridRow = angular.copy(newRow);
var lastChar = getListOfSameLevel(rowId, true); //isParentRow
var parentId = rowId.length > 1 ? rowId.slice(0, rowId.length - 1) : "";
newGridRow.rowId = parentId + getNextChar(lastChar);
$scope.componentList.push(newGridRow);
}

$scope.addChildRow = function(rowId) {
var newGridRow = angular.copy(newRow);
var lastChar = getListOfSameLevel(rowId, false);
if (rowId.length === lastChar.length) {
newGridRow.rowId = rowId + "A";
} else {
var parentId = lastChar.length > 1 ? lastChar.slice(0, lastChar.length - 1) : "";
newGridRow.rowId = parentId + getNextChar(getLastChar(lastChar));
}
$scope.componentList.push(newGridRow);
};

var getNextChar = function(inputChar) {
return String.fromCharCode(inputChar.charCodeAt(0) + 1);
};

var getLastChar = function(fullStr) {
return fullStr.slice(-1);
};

最佳答案

您需要将 newRow.rowId 的初始值从 A 更改为至1并更改 A 下一个数字的起始位置至1addChildRow 函数中,如下所示:

if (rowId.length === lastChar.length) {
newGridRow.rowId = rowId + "1";
}

Here你的数字笨蛋吗

关于javascript - 如何逐行增加数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45460868/

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