gojs2.1.56版本 function ContinuousForceDirectedLayout() { go.ForceDirectedLayout.call(this); this._isObserving = false; this.defaultDirection = go.LayoutDirection.Right; } go.Diagram.inherit(ContinuousForceDirectedLayout, go.ForceDirectedLayout);这段为啥报错啊
时间: 2024-02-06 21:12:41 浏览: 34
在 GoJS 2.1.56 中,使用 `go.Diagram.inherit` 继承类的方式已经被弃用了,可能会导致报错。如果你想让 `ContinuousForceDirectedLayout` 继承自 `go.ForceDirectedLayout`,可以使用 ES6 的 `class` 关键字来定义类,代码示例如下:
```
class ContinuousForceDirectedLayout extends go.ForceDirectedLayout {
constructor() {
super();
this._isObserving = false;
this.defaultDirection = go.LayoutDirection.Right;
}
}
```
这样就可以定义 `ContinuousForceDirectedLayout` 类,并且继承自 `go.ForceDirectedLayout`。同时,你需要确保在使用 `ContinuousForceDirectedLayout` 之前,已经正确地加载了 GoJS 库,并且 `go.LayoutDirection` 被正确定义。
相关问题
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` 被正确定义。
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` 使用了。
相关推荐
![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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)