【发布时间】:2017-08-16 01:37:50
【问题描述】:
我正在使用viewer.getProperties(dbId, onSuccessCallback, onErrorCallback) 方法来获取查看器中对象的属性。我想为所有选定的对象运行该方法,为每个对象提取属性的子集,并将子集呈现在表中。
var subsets = [];
var selectFunctions = [];
handleSelection(selection, addProps, onError);
function handleSelection(selection, onSuccess, onError) {
for (var i = 0; i < selection.length; i++)
selectFunctions.push(_viewer.getProperties(selection[i], onSuccess, onError));
}
function addProps(data) {
var props = [];
for (var prop in data.properties) {
//Add property to props if some condition is true...
}
subsets.push(props);
}
Promise.all(_selectFunctions).then(function () {
console.log("Handled all selections");
//Add subsets to table...
}).catch(function (error) {
console.log("ERRROR");
});
由于 getProperties 是异步运行的,我无法在更新表之前等待所有对象。该表一次更新一个对象,我们宁愿一次更新所有对象。阻塞 IO 不是问题。
正如可能显示的那样,我一直在研究 bluebird.js 中的 Promise.all(),以控制执行并等待所有 getProperties 调用返回,但到目前为止没有成功。
问候, 托瑞斯
【问题讨论】:
标签: node.js autodesk-forge autodesk-viewer