[英]Access object property that is outside of array
我的页面对象是结构化的,因此我拥有一个对象中的所有元素,然后是一个对象数组,其中包含有关可以循环测试最大字符长度和错误文本的字段的数据。
我希望定位器引用数组外部的属性,以便在元素更改时不需要更新该值两次。
以页面对象的片段为例...
module.exports = {
siteName: element(by.id('P662_NAME')),
fields: [
{
name: 'site name',
max: 45,
locator: element(by.id('P662_NAME'))
}
]
}
我试过使用以下方法但没有运气...
this.siteName, this.siteName, module.exports.siteName
有没有办法做到这一点?
试试这个:从这样的文件导出
沙盒: https : //codesandbox.io/s/compassionate-bas-fg1c2
var siteName = "dsdsd";
var fields = [
{
name: "site name",
max: 45,
locator: "dsdsd"
}
];
module.exports = {
siteName,
fields
};;
像这样导入它:
import { siteName } from "./test.js";
console.log(siteName);
您可以做的是将siteName
设置为另一个变量并在您的fields
对象中引用它,如下所示:
let siteName = "foo"; // now, updating this variable will also update the one in fields let fields = [{ // other props locator: siteName }]; console.log(fields[0].locator); // expects "foo" // module.exports = { siteName, fields };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.