0

所以我从forge改编了这个例子

我目前可以通过面板检索所有问题,我正在尝试按截止日期等属性对多个问题进行排序。我尝试了几种不同的 sortBy() 方法,但不确定如何让它工作。

有任何想法吗?这是下面的代码,我在哪里输入 sortBy 方法?

BIM360IssueExtension.prototype.showIssues = function () {
  var _this = this;

  //remove the list of last time
  var pushPinExtension = _this.viewer.getExtension(_this.pushPinExtensionName);
  pushPinExtension.removeAllItems();
    pushPinExtension.showAll();
  var selected = getSelectedNode();

  _this.issues.forEach(function (issue) {
    var dateCreated = moment(issue.attributes.created_at);

    // show issue on panel
      if (_this.panel) {
        _this.panel.addProperty('Title', issue.attributes.title, 'Issue ' + issue.attributes.identifier);
        _this.panel.addProperty('Assigned to', issue.attributes.assigned_to, 'Issue ' + issue.attributes.identifier);
      //_this.panel.addProperty('Location', stringOrEmpty(issue.attributes.location_description), 'Issue ' + issue.attributes.identifier);
        _this.panel.addProperty('Version', 'V' + issue.attributes.starting_version + (selected.version != issue.attributes.starting_version ? ' (Not current)' : ''), 'Issue ' + issue.attributes.identifier)
        _this.panel.addProperty('Due Date', issue.attributes.due_date, 'Issue ' + issue.attributes.identifier);
      _this.panel.addProperty('Created at', dateCreated.format('MMMM Do YYYY, h:mm a'), 'Issue ' + issue.attributes.identifier);
    }

    // add the pushpin
    var issueAttributes = issue.attributes;
    var pushpinAttributes = issue.attributes.pushpin_attributes;
    if (pushpinAttributes) {
      issue.type = issue.type.replace('quality_', ''); // temp fix during issues > quality_issues migration
      pushPinExtension.createItem({
        id: issue.id,
        label: issueAttributes.identifier,
        status: issue.type && issueAttributes.status.indexOf(issue.type) === -1 ? `${issue.type}-${issueAttributes.status}` : issueAttributes.status,
        position: pushpinAttributes.location,
        type: issue.type,
        objectId: pushpinAttributes.object_id,
        viewerState: pushpinAttributes.viewer_state
      });
    }
  })
}
4

1 回答 1

1

首先,您需要一些库进行排序,例如Underscore。您可以简单地使用他们的 CDN:

<script src="https://underscorejs.org/underscore-min.js"></script>

然后,在加载Issues和列出它们之前(例如示例中的这一行),尝试类似:

// sort by title
_this.issues = _.sortBy(_this.issues, function (i){return i.attributes.title});

// or sort by due date (this Date.parse returns an int representing the date)
_this.issues = _.sortBy(_this.issues, function (i){return Date.parse(i.attributes.due_date)});

顺便说一句,您需要处理due_date未指定 (null)的情况

于 2018-12-07T13:24:29.870 回答