✍️
Web Application
  • Cookie
  • Intro
    • HTTP
  • Cookie
    • Counting Cookie
    • Shopping Cart Using Cookie
    • Shopping Cart Page:id
    • Shopping Cart Page
    • Cookie and Security
  • Session
    • Intro
    • Session and Cookie
    • Session with Express
    • Login function using session
    • How to store session data
    • store as file
    • store in mysql DB
    • Store Session in OrientDB
  • Security Password
    • salt
    • PBKDF2
    • Log in with encrypted password
    • PassportJS
    • Untitled
  • Federation Authentication
    • Intro
    • Facebook Authentication
    • FB Auth Summary
  • refactoring
    • template engine : pug extends, include
    • Modularity
    • Divide Router
Powered by GitBook
On this page

Was this helpful?

  1. Cookie

Shopping Cart Using Cookie

PreviousCounting CookieNextShopping Cart Page:id

Last updated 4 years ago

Was this helpful?

기능 명세

  1. product 홈페이지

제품 목록이 나온다. '제품 n '의 'add' 를 누르면 shopping cart 페이지로 이동한다. => 제품 1(제품id)의 add를 누르면 count/1(=제품 id) 로 접속한다. 한번 더 누르면 cart 페이지에서 수량이 증가한다. (누를 때마다 증가한다)

Products List

  • Product 1 . add

  • Product 2 . add

Cart

Nodejs에서 반복문 사용하기(for in 문)

var products = {
    1:{title:'Product1'},
    2:{title:'Product2'}
};
app.get('/products',(req,res)=>{
    for(var name in products) {//객체의 프로퍼티 이름이 name에 담긴다! 1->2->..
        console.log(products[name]);//products[1] = {title:'Product1'}, products[2] = {title:'Product2'}
    }
    res.send('Products');
});

product 배열에서 객체의 title값만 가져올

var products = {
    1:{title:'Product1'},
    2:{title:'Product2'}
};
app.get('/products',(req,res)=>{
    for(var name in products) {//객체의 프로퍼티 이름이 name에 담긴다! 1->2->..
        console.log(products[name].title);//products[1] = {title:'Product1'}, products[2] = {title:'Product2'}
    }
    res.send('Products');
});

실행 결과