Sou*_*ura 0 javascript node.js typescript
我正在开发节点js API,我正在通过URL查询数据
get_posts_default?pageId=ge4JqBn9F0srzHnVFHmh&asking_post=false&asking_responce=false&maxSort=-1&minSort=-1&limit=20
Run Code Online (Sandbox Code Playgroud)
这是负责处理此请求的函数
public async get_poset_list(userDeta: hs_I_fb_en_user_auth_paylode,pageId:string,asking_post:boolean,asking_responce:boolean,maxSort:number,minSort:number,limit:number):Promise<hs_I_fb_en_post_return[]>{
try {
hs_d_w("Is asking post: - "+asking_post);
hs_d_w("Limit: - "+limit);
if(asking_post===true){
hs_d_w("Asking post true");
if(minSort<=-1 && maxSort<=-1){
hs_d_w("Asking post Defolt");
return this._postQueryes.get_only_poses(pageId,limit);
}else{
if(minSort>-1){
hs_d_w("Asking post MIn");
return this._postQueryes.get_only_poses_min(pageId,minSort,limit);
}
if(maxSort>-1){
hs_d_w("Asking post Max");
return this._postQueryes.get_only_poses_max(pageId,maxSort,limit);
}
hs_d_w("Asking post None");
return [];
}
}else{
if(minSort<=-1 && maxSort<=-1){
hs_d_w("Asking talk Defolt");
return this._postQueryes.get_only_talkes(pageId,limit);
}else{
if(minSort>-1){
hs_d_w("Asking talk min");
return this._postQueryes.get_only_talkes_min(pageId,minSort,limit);
}
if(maxSort>-1){
hs_d_w("Asking talk max");
return this._postQueryes.get_only_talkes_max(pageId,maxSort,limit);
}
hs_d_w("Asking talk none");
return [];
}
}
} catch (e) {
hs_d_w("get_poset_list : " + e);
return Promise.reject(e)
}
}
Run Code Online (Sandbox Code Playgroud)
现在如果我调用set calling_post = false或ask_post = true,它总是调用此函数的主要else区域
return this._postQueryes.get_only_talkes(pageId,limit);
Run Code Online (Sandbox Code Playgroud)
这个.
我不明白为什么会这样?有人可以帮我这个吗?
当你得到req.query它的东西时总会返回一个String.因此,请确保将其转换为布尔值
const variable = (variable == 'true')
// or
const variable = (variable === 'true')
Run Code Online (Sandbox Code Playgroud)
另外,当变量是布尔值时,您不必显式检查===.这也行
if(foo) {
} else {
}
Run Code Online (Sandbox Code Playgroud)
编辑:正如@Kamalakannan所说Boolean('string')不会奏效.我很抱歉.
| 归档时间: |
|
| 查看次数: |
539 次 |
| 最近记录: |