zoukankan      html  css  js  c++  java
  • new-Category-default category show

    动态添加category

    const categories = ['fruit', 'vagetable', 'diary', 'unique'];
    app.get(
    '/products/new', (req, res) => { res.render('products/new', { categories }) })
    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>New product</title>
    </head>
    
    <body>
        <h1>Add a product </h1>
        <form action="/products" method="POST">
            <label for="name">Name</label>
            <input type="text" name="name" id="name" placeholder="product name">
            <label for="price">price</label>
            <input type="number" name="price" id="price" placeholder="price">
            <label for="category">Select category</label>
            <select name="category" id="category">
                <%for(let category of categories){%>
                    <option value="<%=category>">
                        <%=category>
                    </option>
                    <%}%>
            </select>
            <button>Submit</button>
            <!-- Submit按钮一旦点击,提交页面/products, post,跟index.js里面的app.post('/products',...)连接着 -->
        </form>
    </body>
    
    </html>

    new.ejs

    <!
    DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>New product</title> </head> <body> <h1>Add a product </h1> <form action="/products" method="POST"> <label for="name">Name</label> <input type="text" name="name" id="name" placeholder="product name"> <label for="price">price</label> <input type="number" name="price" id="price" placeholder="price"> <label for="category">Select category</label> <select name="category" id="category"> <%for(let category of categories){%> <option value="<%=category>"> <%=category> </option> <%}%> </select> <button>Submit</button> <!-- Submit按钮一旦点击,提交页面/products, post,跟index.js里面的app.post('/products',。。。)连接着 --> </form> </body> </html>
    edit.ejs

    <!
    DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Edit product</title> </head> <body> <h1>Edit a product </h1> <form action="/products/<%=product._id%>?_method=PUT" method="POST"> <label for="name">Name</label> <input type="text" name="name" id="name" placeholder="product name" value="<%=product.name%>"> <label for="price">price</label> <input type="number" name="price" id="price" placeholder="price" value="<%=product.price%>"> <label for="category">Select category</label> <select name="category" id="category"> <%for(let category of categories){%> <option value="<%=category%>" <%=product.category===category ? 'selected' : '' %>><%=category%> </option> <%}%> </select> <button>Submit</button> <!-- Submit按钮一旦点击,提交页面/products, post,跟index.js里面的app.post('/products',......)连接着 --> </form> <a href="/products/<%=product._id%>">Cancel</a> </body> </html>
     <option value="<%=category%>" <%=product.category===category ? 'selected' : '' %>><%=category%>
     </option>
    设置默认显示的category。
  • 相关阅读:
    分布式服务框架 Zookeeper — 管理分布式环境中的数据
    分布式消息队列(二)
    分布式消息队列(一)
    数据库事务的四大特性以及事务的隔离级别
    php--yii2.0的安装
    php--字符串函数分类总结
    一张表有三个字段:id(城市id) Cityname(城市名) Privence(所属省份)如果要统计每个省份有多少城市请用SQL实现。
    TP自带的缓存机制
    php——n维数组的遍历——递归
    php--分享插件
  • 原文地址:https://www.cnblogs.com/LilyLiya/p/14397629.html
Copyright © 2011-2022 走看看