我有以下index.js文件;
var Lob = require('lob')('test_6afa806011ecd05b39535093f7e57757695');
var residence = require('./addresses.json');
console.log(residence.residence.length);
for (i = 0; i < residence.residence.length; i++) {
console.log(residence.residence[i].name);
Lob.addresses.create({
name: 'residence.residence[i].name',
}, function(err, res) {
console.log(err, res);
});
}
当我console.log( residence.residence[i].name )
时,相应的回复&#34; RESIDENT&#34;出现。
但是,我试图在Lob.addresses.create({
下的Base[] collection;
foreach(var item in collection){
if((item as TypeYouWhant) == item){
...
}
}
下的帖子请求中传递与该值相同的值。
如何将该值传入我的键值对作为&#34; name的值:&#34;?
答案 0 :(得分:3)
由于您使用了引号,您似乎传入了一个字符串'residence'residence [i] .name'...删除引号:
for (i = 0; i < residence.residence.length; i++) {
console.log(residence.residence[i].name);
Lob.addresses.create({
name: residence.residence[i].name,
}, function(err, res) {
console.log(err, res);
});
}