function ContinuousForceDirectedLayout() { go.ForceDirectedLayout.call(this); this._isObserving = false; this.defaultDirection = go.LayoutDirection.Right; } go.Diagram.inherit(ContinuousForceDirectedLayout, go.ForceDirectedLayout); 报错了Uncaught TypeError: Cannot read properties of undefined (reading 'Right')
时间: 2024-01-21 21:04:38 浏览: 30
如果你在运行代码时出现了 `Uncaught TypeError: Cannot read properties of undefined (reading 'Right')` 的错误,说明在设置 `defaultDirection` 属性时,`go.LayoutDirection` 未被正确加载。
请确保在使用 `ContinuousForceDirectedLayout` 之前,正确地加载了 GoJS 库,并且 `go.LayoutDirection` 被正确定义。可以在 HTML 页面中将以下代码加入到 `<head>` 标签中,以加载 GoJS 库:
```
<script src="https://unpkg.com/gojs/release/go.js"></script>
```
同时,还需要确保在 `ContinuousForceDirectedLayout` 之前,已经定义了 `go` 对象,并且 `go.LayoutDirection` 被正确定义。可以在 `<script>` 标签中添加以下代码:
```
var go = go || {};
go.LayoutDirection = go.LayoutDirection || {};
go.LayoutDirection.Right = 1;
```
这样就可以确保 `go.LayoutDirection` 被正确加载,并且 `defaultDirection` 属性可以被正确设置。
相关问题
function ContinuousForceDirectedLayout() { go.ForceDirectedLayout.call(this); this._isObserving = false; this.defaultDirection = go.LayoutDirection.Right; 报错了
如果你将 `defaultDirection` 属性加入到 `ContinuousForceDirectedLayout` 的构造函数中,但是出现了报错,可能是因为 `defaultDirection` 属性在 `go.ForceDirectedLayout` 中不存在。
你可以尝试在 `ContinuousForceDirectedLayout` 的构造函数中添加以下代码,以判断 `defaultDirection` 属性是否可用:
```
console.log(go.ForceDirectedLayout.prototype.hasOwnProperty('defaultDirection'));
```
如果输出结果为 `false`,说明 `go.ForceDirectedLayout` 中并没有 `defaultDirection` 属性,因此你需要将 `defaultDirection` 属性加入到 `ContinuousForceDirectedLayout` 中:
```
function ContinuousForceDirectedLayout() {
go.ForceDirectedLayout.call(this);
this._isObserving = false;
this.defaultDirection = go.LayoutDirection.Right;
}
go.Diagram.inherit(ContinuousForceDirectedLayout, go.ForceDirectedLayout);
```
这样,`defaultDirection` 属性就可以被 `ContinuousForceDirectedLayout` 使用了。
gojs2.1.56版本 function ContinuousForceDirectedLayout() { go.ForceDirectedLayout.call(this); this._isObserving = false; this.defaultDirection = go.LayoutDirection.Right; } go.Diagram.inherit(ContinuousForceDirectedLayout, go.ForceDirectedLayout);这段为啥报错啊 请用es5解决
如果你使用 GoJS 2.1.56 版本,可以使用 ES5 的方式来定义 `ContinuousForceDirectedLayout` 类并继承自 `go.ForceDirectedLayout`。代码示例如下:
```
function ContinuousForceDirectedLayout() {
go.ForceDirectedLayout.call(this);
this._isObserving = false;
this.defaultDirection = go.LayoutDirection.Right;
}
// 设置类的原型为go.ForceDirectedLayout的原型
ContinuousForceDirectedLayout.prototype = Object.create(go.ForceDirectedLayout.prototype);
// 将类的构造函数设置为ContinuousForceDirectedLayout
ContinuousForceDirectedLayout.prototype.constructor = ContinuousForceDirectedLayout;
```
这样就可以使用 ES5 的方式来定义 `ContinuousForceDirectedLayout` 类并继承自 `go.ForceDirectedLayout` 了。同时,你需要确保在使用 `ContinuousForceDirectedLayout` 之前,已经正确地加载了 GoJS 库,并且 `go.LayoutDirection` 被正确定义。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)