sorting - BIM360 问题 SortBy()
问题描述
所以我从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
});
}
})
}
解决方案
首先,您需要一些库进行排序,例如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)的情况
推荐阅读
- java - 是否可以在 main 方法之外使用 Scanner 并仍然调用它?
- r - 如何编写读取文本文件目录、更改它们并保存到同一目录中的 R 函数
- haskell - 每当我尝试在 Cabal 上安装新软件包时,它都会尝试安装以前失败的安装但失败
- python - 如何在 Python 中修改 Protocol-Buffers ScalarMapContainer?
- reactjs - 在同一浏览器中保持用户会话以做出反应
- reactjs - Apollo-graphql 突变中的“mutation_root”是什么?我收到错误消息,提示“mutation_root”中找不到字段
- google-cloud-platform - Terraform GCP service_account vs project vs org
- python - AttributeError:导入 keras 时模块“tensorflow”没有属性“name_scope”
- java - 有没有一种简单的方法可以使用 Java 将术语插入到 Elasticsearch QueryDSL 中?
- php - 如何使用 PHP 从 Rapid API 获取 JSON 数据