О сравнении строк в nodejs. почему возвращаемое значение не True? - PullRequest
0 голосов
/ 14 февраля 2020
else if (pathname === '/reservation_process')
     {
         var body = '';
         request.on('data', function(data){
             body = body + data;
         });

         request.on('end', function(){
             var post = queryString.parse(body);
             console.log(post);
             var customer_id = post.customer_id;
             var customer_phone = post.customer_phone;
             var customer_date = post.customer_date;
             var customer_require = post.customer_require;
             fs.writeFile(`../data/${customer_id}`, customer_phone+'\n'+customer_date+'\n'+customer_require, 'utf8', function(err){
                 response.writeHead(302, {Location:`/`}); //redirection, code 302 means redirection.
                 response.end(); 
             });
         });

     }

Входные данные сохраняются в / data /% {custmoer_id}, затем данные создаются. и ....

while( i < filelist.length){
                        console.log("filelist : "+i+filelist[i]); 

07:40:40 0|main  | filelist : 0.DS_Store
07:40:40 0|main  | filelist : 1CSS
07:40:40 0|main  | filelist : 2HTML
07:40:40 0|main  | filelist : 3JavaScript
07:40:40 0|main  | filelist : 4mongho
07:40:40 0|main  | filelist : 5node
07:40:40 0|main  | filelist : 6test_confirm
07:40:40 0|main  | filelist : 7undefined
07:40:40 0|main  | filelist : 8김영호

Печать списка файлов.

else if(pathname === '/reservation_check'){
             var template = templateHTML("영호스튜디오", '<h2>예약확인 페이지</h2>',
             `
             <form action="/reservation_check/show_inf" method="post">
             <p><input type="text" name="confirm_id" placeholder="고객님의 성함"></p>
             <p><input type="text" name="confirm_phone" placeholder="고객님의 연락처"></p>
             <p><input type="submit"></p>
             </from>
             `);
             response.writeHead(200);
             response.end(template);

         }

и перенаправление формы на "/reservation_check/show_inf".

Я сравниваю список файлов и сообщение .confirm_id

while( i < filelist.length){
if( filelist[i] == post.confirm_id) {
                            console.log("find it!");
                            fs.readFile(`../data/${filelist[i]}`, 'utf8', function(err, data){
                            console.log(data);
                            });
                        }
                    }

когда я сохранял данные, мой ввод "김영호" в customer_id и в verify_id также "김영호" Так что я думаю, filelist [8] == post.confirm_id. но if( filelist[8] == post.customer_id ) возвращаемое значение ложно ...

я не знаю, почему возвращаемое значение ложно ... пожалуйста, помогите мне решить эту проблему ...: (

и

console.log(typeof(post.confirm_id)); 
console.log(typeof(filelist[8])); 
console.log(post.confirm_id); 
console.log(filelist[8]); 

этот результат равен

08:17:41 0|main | string 
08:17:41 0|main | string 
08:17:41 0|main | 김영호 
08:17:41 0|main | 김영호
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...