BIM360 问题 SortBy()
BIM360 Issues SortBy()
所以我正在改编这个 example 来自 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
之后和列出它们之前(例如 this line at the sample),尝试类似的操作:
// 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
的情况(空)
所以我正在改编这个 example 来自 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
之后和列出它们之前(例如 this line at the sample),尝试类似的操作:
// 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
的情况(空)