inflearn logo
강의

Khóa học

Chia sẻ kiến thức

Một trại huấn luyện phát triển toàn diện thực sự dành cho những người không chuyên ngành

Tích hợp Web và API & Xử lý ngày tháng với dayjs

id 값 문제인데 해결을 못하겠습니다.

283

sg HYUN

15 câu hỏi đã được viết

1

local host 로 들어가서 축구공위에 마우스를 올리면 아래 products/0 으로 나옵니다.. 물론 클린하면 아무데이터도 나오지 않고 2번쨰 그림을 클릭하면 1번째 상세 정보가 표출됩니다. 

db값은  id:1 2 3 으로 되어 있으나, localhost 상에는 0, 1, 2 로 표기되있는듯 합니다. 

왜 값을 일치 시키지 못하는지 강의를 다시 보면서 문제를 찾아봐도 잘 해결이 되지 않습니다. ㅠ 아직 이해가 많이 부족한듯 합니다. 설명 부탁드립니다. 

<Switch>
      <Route exact={true} path={"/"}>
        <MainPageComponent/>
      </Route>
      <Route exact={true} path="/products/:id">
        <ProductPage/>
      </Route>
      <Route exact={true} path="/upload">
        <UploadPage/>
      </Route>
    </Switch>


app.get("/products/:id", (req,res)=>{
  const params = req.params;
  const {id} = params;
  models.Product.findOne({
    where : {
      id:id,
    },  
  }).then((result)=>{
    console.log("PRODUCT : "result);
    res.send({
      product : result
    });
  }).catch((error)=>{
    console.error(error);
    res.send("상품 조회에 에러가 발생했습니다.");
  });
});

그리고... 해당 강의 전의 SQLite 데이터 순서와 현재강의의 데이터 순서가 선생님은 바뀌었는데... 저는 그렇지 않습니다.. ㅠㅠ  이것까지만의 드립니다. 

app.get("/products", (reqres=> {
  models.Product.findAll({
    order: [["createdAt""DESC"]],
    attributes:[
      'id''name''price''createdAt','seller','imageUrl'
    ],
  })  
  .then((result)=>{
    console.log("PRODUCTS : "result);
    res.send({
      products : result
    });
  }).catch((error)=>{
    console.error(error);
    res.send("에러 발생");
 })
});

 

api dayjs express node.js react-native HTML/CSS tensorflow nodejs javascript react 머신러닝 배워볼래요?

Câu trả lời 2

1

sg HYUN

네!! 우선 web부분

function MainPage(){
        const[productssetProducts]=React.useState([]);
        
        React.useEffect(
            function(){
                axios
                .get("http://localhost:8080/products")
                .then(function(result){
                        const products = result.data.products;
                        setProducts(products);
                }).catch(function(error){
                    console.error('에러 발생 : ',error);
                });
            },[])

    return (
        <div>            
                <div id="banner">
                    <img src="images/banners/banner1.png"/>
                </div>
                <h1>퍈매되는 상품들</h1>
                <div id="product-list">                                       
                        {products.map(function(productindex){
                            return (
                            <div className = "product-card">
                                <Link className="product-link" to={`/products/${index}`}>
                                                       {/* to={"/products/"+index} 를 위에 es6 문법으로 */}
                                <div>
                                <img 
                                className="product-img"  
                                src={product.imageUrl}
                                />
                            </div>
                            <div className="product-contents">
                                <span className="product-name">
                                    {product.name}
                                </span>
                                <span className="product-price">
                                    {product.price}
                                </span>
                                <div className="product-seller">
                                    <img className="product-avatar" src="images/icons/avatar.png"/>
                                    <span>{product.seller}</span>
                                </div>                            
                            </div>
                            </Link>
                            </div>
                            );
                        })}
                </div>                                                                                 
                </div>   

추가적으로

아래의 최 상단 2줄은 자동으로 추가되어 제가 주석처리했습니다.

// const { DataTypes } = require("sequelize/types")
// const { sequelize } = require(".")

module.exports = function(sequelizeDataTypes){
    const product = sequelize.define('Product',{
        name:{
            type: DataTypes.STRING(20),
            allowNull: false

        },
        price :{
            type: DataTypes.INTEGER(10),
            allowNull: false

        },
        seller :{
            type: DataTypes.STRING(30),
            allowNull: false

        },
        description :{
            type: DataTypes.STRING(300),
            allowNull: false

        },
        imageUrl : {
            type: DataTypes.STRING(300),
            allowNull: true

        }
    });
    return product;
}

0

grab

웹 쪽 코드를 보면 to 속성값으로 ${index}가 들어가 있네요!! product.id로 바꿔보시겠어요~?

<Link className="product-link" to={`/products/${index}`}>

0

sg HYUN

수정해보고 다시 리마인드해보겠습니다. 너무 감사합니다!! :)))

0

grab

안녕하세요~!

ProductPage 코드를 보여주실 수 있으실까요~?

[해결]그랩님 답변 주세요.

0

193

2

그랩님의 답변을 기다립니다/102강 전반적인 에러

0

165

2

[그랩님께]101강 안드로이드 에러들(Key prop)해결방법 궁금합니다.

0

139

2

[재질문][그랩님 답변 부탁드립니다]101강

0

164

2

[그랩님 답변 부탁드립니다]101강 Axios 에러와 502 Bad Gateway 질문

0

120

2

Ngrok 설치 후 forwarding Url 에러

0

148

2

[그랩님께,Ngrok 악성코드 인식 해결방법]질문 드립니다.

0

255

2

Ngrok 설치 후 forwarding Url로 연결 불가

0

158

1

그랩님,[꼭] 답변 부탁드립니다.

0

76

1

[꼭][[꼭] 그랩님, 답변 부탁드립니다], Failed to load resource: the server responded with a status of 404 (Not Found) 상품 상세 페이지 질문입니다.

0

162

1

6강/7강 수업

0

56

1

그랩님, 상품 상세 페이지 에러와 의문점 질문드립니다.

0

105

2

그랩님, 해결되지 않은 에러 메시지 [꼭] 답변 부탁 드립니다.

0

148

2

[재 질문]Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?

0

95

1

Cannot read properties of undefined (reading 'map') TypeError: Cannot read properties of undefined (reading 'map') 에러 해결 어떻게 하나요?

0

134

2

일반적인 css 꾸미기에서 width와 height의 값?

0

98

2

Windows에서의 업로드 후 홈화면 상품이미지 오류 해결방법

0

204

1

그랩마켓 웹화면 구현하기 -2 질문입니다.

0

127

1

react에 반영이 되지 않습니다.

0

252

1

터미널 npm install -g create-react-app 작성 후 오류

0

430

1

create-react-app my app 실행 시 에러

0

358

2

포스트맨 질문

0

105

1

<꼭 답변 부탁 드립니다>그랩선생님, [컴포넌트 사용하기] 강의에서 질문 있습니다.

0

269

2

그랩선생님, 질문 답변 부탁 드립니다.vscode에서 npm install -g create-react-app 입력 후 에러 입니다.

0

494

2