我有两个职能。我的第一个函数返回一个对象,我想在第二个函数中使用该对象。我所做的是在这里:
// where accid = res.rows.item(i).accountId; somewhere in code which outputs accid=16757
replaceIds(accid){
console.log("yet to be done line number: 131",accid);
let result={};
let addressid;
let communicationId;
this.configProvider.Customquery("Select * from addresses where accountid=? order by id DESC limit 1",[accid]).subscribe(res=>{
// console.log("res",res);
if (res.rows!=undefined)
// var companyId=res.rows.item(i).compnayId;
for (var i = 0; i < res.rows.length; i++) {
// console.log("result",res.rows.item(i));
addressid=res.rows.item(i).addressId;
}
this.configProvider.Customquery("Select * from communications where accountid=? order by id DESC limit 1",[accid]).subscribe(res1=>{
// console.log("res",res1);
if (res1.rows!=undefined)
// var companyId=res.rows.item(i).compnayId;
var newItem=[];
for (var i = 0; i < res1.rows.length; i++) {
// console.log("result",res1.rows.item(i));
communicationId=res1.rows.item(i).communicationId;
}
result={addressid,communicationId};
console.log("ids",result,typeof(result));
return result;
});
});
}
第二个功能是:
OrdersJson(){
var flag:boolean=false;
var val:boolean=true;
this.configProvider.Customquery("Select * from Orders where synced=?",[flag]).subscribe(res=>{
if (res.rows!=undefined)
var newItem=[];
for (var i = 0; i < res.rows.length; i++) {
const accid:number=res.rows.item(i).accountId;
console.log("replcement of ids is started",typeof(accid));
const getIds=this.replaceIds(accid);
console.log("Ids in Order Json",getIds);
}
});
}
但是控制台将getIds
打印为undefined
。请让我知道我的代码有什么问题。
答案 0 :(得分:0)
结果变量既不是对象也不是数组。
答案 1 :(得分:0)
add_filter( 'gettext', function( $translated_text, $text, $domain ){
if ( $text == 'Bid Value' )
$translated_text = 'Příhoz';
return $translated_text;
}, 10, 3 );
结果:
constructor(){
this.createJson();
}
replaceIds(accid:string){
let result={};
result={addressid:1234,communicationid:3456};
return result;
}
createJson(){
const accid = '';
const getIds=this.replaceIds(accid);
console.log("Ids in Order Json",getIds);
}