cesiumlab / cesiumlab/XbsjEarthUI

我在类里加了两个属性, 但是this.toJSON()方法不会把这两个属性转成JSON请问 怎样设置才能保存这两个属性呢?

Open
#67 0 comments 0 reactions 0 assignees View on GitHub
documentation question
Dominant language
JavaScript
Stars
734
Forks
193
PR merge metrics
No merged PRs in 30d

Description

@vtxf 求问~ 我在类里加了两个属性, 但是this.toJSON()方法不会把这两个属性转成JSON请问 怎样设置才能保存这两个属性呢?

![image](https://user-images.githubusercontent.com/13550568/71968275-8b52a880-323f-11ea-860f-73866b954fd0.png)

![image](https://user-images.githubusercontent.com/13550568/71968281-8e4d9900-323f-11ea-83f9-a4c7215c6cd4.png)

---

可以参考自定义图元库中的写法:

https://github.com/cesiumlab/CustomPrimitive-EarthSDK/blob/master/src/Tube.js

1 首先定义defaultOptions

[图片]
![image](https://user-images.githubusercontent.com/13550568/71968307-9a395b00-323f-11ea-95f4-eec9673b5dab.png)

2 然后将其与自定义的类关联起来:
Tube.defaultOptions = defaultOptions;
[图片]
![image](https://user-images.githubusercontent.com/13550568/71968314-9efe0f00-323f-11ea-90a7-7d311b86537c.png)

3 注意代码中就不要再用 XE.MVVM.extend(...)来定义相关变量了

4 通过以上方法定义的变量是可以存储的

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by locating the class that calls this.toJSON() and inspect how its properties are declared, especially use of XE.MVVM.extend(...). Compare that serialization setup with src/Tube.js in the linked CustomPrimitive-EarthSDK example. Done means the two added properties appear in the serialized JSON and can be saved and restored.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.