当我尝试使用 pkgcloud 并且属性未定义时,我遇到了一个奇怪的未定义错误length
:
var pkgcloud = require('pkgcloud');
var Q = require('q');
router.get('/', function(req, res, next) {
var conn = pkgcloud.compute.createClient({
provider: 'openstack', // required
username: 'demo', // required
password: 'azerty', // required
authUrl: 'http://192.168.0.242:5000' ,
region_name :'RegionOne'// required
});
console.log(conn);
在这个阶段我可以可视化 object 的不同方法conn
,但是错误是在 for 循环中产生的:
var d = Q.defer();
conn.getImages(function(err, images) {
for (var i=0; i<images.length; i++) {
console.log("id: " + images[i].id);
console.log("name: " + images[i].name);
console.log("created: " + images[i].created);
console.log("updated: " + images[i].updated);
console.log("status: " + images[i].status + "\n");
}
if (err) {
console.log("erreur");
d.reject(err);
} else {
console.log("juste");
d.resolve();
}
});
res.render('index', { title: 'Express' });
});