【问题标题】:Problems with getting the properties of an ID when looping over all Ids循环遍历所有 ID 时获取 ID 属性的问题
【发布时间】:2017-04-30 02:47:07
【问题描述】:

我有兴趣获取所有 dbId 元素的属性。为此,我只是循环遍历我的 dbIds 数组并使用Forge Viewer 提供的getProperties 函数。

  someFunction() {

    const instanceTree = this.viewer.model.getData().instanceTree;

    const allDbIds = Object.keys(instanceTree.nodeAccess.dbIdToIndex);

    console.log('all DbIds');
    console.log(allDbIds);

    // This will give the correct Properties
    // this.viewer.getProperties(5, (result) => {
    //   console.log(result)
    // })

    allDbIds.forEach((dbId) => {

      this.viewer.getProperties(dbId, (result) => {
        console.log('result:');
        console.log(result);

      }, (err) => {
        console.log('err');
        console.log(err);
      });
    });
  }

当我直接访问特定的 dbId 时,我得到了正确的属性数组。但是,当遍历所有 dbId 并调用 getProperties 函数时,只有前两个 dbId 返回属性,而所有其他 dbId 仅返回空数组。此外,前两个数组很大,似乎包含其他属性。 --> Link to console output

有人知道我在这里做错了什么吗?已经谢谢了!

【问题讨论】:

  • 看起来和听起来像是同步/异步问题...

标签: autodesk-forge autodesk-viewer


【解决方案1】:

与其在客户端页面上迭代属性,更好的方法可能是通过模型衍生 API 一次查询所有属性。请参阅这些参考资料:

https://developer.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-metadata-GET/

https://developer.autodesk.com/en/docs/model-derivative/v2/reference/http/urn-metadata-guid-properties-GET/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-23
    • 1970-01-01
    相关资源
    最近更新 更多