gpt4 book ai didi

javascript - 更改 forEach 循环中的选择选项

转载 作者:行者123 更新时间:2023-12-04 01:47:54 25 4
gpt4 key购买 nike

我有以下测试代码:

ID = {
CreatedBy: { id: 'createdBy' },
ModifiedBy: { id: 'modifiedBy' }
}

Profile = {
All: { text: 'All', val: 0 },
Sys: { text: 'system_system@system.com', val: 1 },
Test: { text: 'test_user@live.com', val: 2 }
}

changeSelect(dataId: EnumElement[], params: UserEnum[]) {
dataId.forEach((data) => {
params.forEach((elem) => {
var label = data.id+ ' - Check option changed to - ' + elem.text;
it(label, () => {
return element(by.xpath('//select[@id="' + data.id + '"]/option[@value = "' + elem.val + '"]')).click();
});
});
}

在我的测试中,我使用如下参数调用 changeSelect() 函数:

changeSelect([ID.CreatedBy, ID.ModifiedBy], [Profile.Sys, Profile.Test]);

正如预期的那样,我的 changeSelect() 函数将输出:

createdBy - Check option changed to - system_system@system.com
createdBy - Check option changed to - test_user@live.com
modifiedBy - Check option changed to - system_system@system.com
modifiedBy - Check option changed to - test_user@live.com

但这不是我想要的输出。我怎样才能调整我的循环来实现下面的输出?

createdBy - Check option changed to - system_system@system.com
modifiedBy - Check option changed to - test_user@live.com

最佳答案

为什么不使用简单的 for?

changeSelect(dataId, params) {
for(i = 0; i < dataId.length; i++){
var data = dataId[i];
var elem = params[i];
var label = data.id + ' - Check option changed to - ' + elem.text;
it(label, () => {
return element(by.xpath('//select[@id="' + data.id + '"]/option[@value = "' + elem.val + '"]')).click();
}
}
}

关于javascript - 更改 forEach 循环中的选择选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25813910/

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