TypeError:无法读取属性'某些内容'未定义的。无法推入阵列

时间:2018-01-07 08:34:12

标签: javascript node.js web

enter image description here

<% include partials/header.ejs%>
<div class="container">
    <div id="inputform">
        <form action="/<%=subject.name%>/courses" method="POST">
            <div class="form-group">
                <label for="title">Title:</label>
                <input type="text" id="title" name="courses[title]" placeholder="Title" style="width:600px">
            </div>

            <div class="form-group">
                <div id="wmd-button-bar"></div>
                <textarea id="wmd-input" name="courses[content]" class="wmd-input"></textarea>
            </div>

            <div class="form-group">
                <div id="wmd-preview" class="wmd-panel wmd-preview"></div>
            </div>

            <input class="btn btn-primary btn-md" type="submit">

        </form>
    </div>
</div>

})

这是我在访问主题路线时编写的用于查看日志的代码,这就是我得到的。

enter image description here

所以&#34; Python&#34;数据,有一个空数组&#34;课程&#34;

这是新表格

enter image description here

app.post("/:subject/courses", function (req, res) {
    Subject.find({name: req.params.subject}, function (err, theSubject) {
        if (err) {
            res.redirect("/")
            console.log(err)
        } else {
            Course.create(req.body.courses, function (err, createdCourse) {
                if (err) {
                    console.log(err)
                } else {
                    console.log("===========theSubject===========");
                    console.log(theSubject);
                    console.log("===========theSubject[0]===========");
                    console.log(theSubject[0]);
                    console.log("===========req.body.courses===========");
                    console.log(req.body.courses);
                    console.log("===========createdCourse===========");
                    console.log(createdCourse);
                    console.log("===========");
                    theSubject[0].courses.push(createdCourse);
                    theSubject[0].save();
                    res.redirect("/:subject")
                }
            })
        }
    })
})

//课程后路线

$receipt = "SELECT * FROM receipt_tbl WHERE receipt_no = '$no' "; 
$receipt_fetch = mysqli_query($con,$receipt) or die("we");
$count = mysqli_num_rows($receipt_fetch);
if (isset($_POST['submit'])){    
    for($num=0;$num<$count ; $num++) {
            $item =$_POST['item'][$num];
            $quantity = $_POST['quantity'][$num];
            $price = $_POST['price'][$num];
            $discount = $_POST['discount'][$num];
            $query2 = "UPDATE `receipt_tbl` SET `receipt_no`='$rcpt',`item`='$item',`quantity`='$quantity',`price`='$price',`discount`='$discount' WHERE receipt_no = '$no'"; 
            $update2 = mysqli_query($con,$query2) or die("we2");     
    }
}

enter image description here

我真的不明白我为什么会这样做无法阅读财产&#39;课程&#39;未定义的

1 个答案:

答案 0 :(得分:1)

使用Error in randomForest.default(m, y, ...) : sampsize should be of length one重定向时,它会创建一个新的res.redirect('/:subject'),它实际上不包含任何参数,只包含一个硬编码字符串。而方法request需要这样的{{1} }}或app.get('/:subject')/python

所以解决方案就是,

/java

希望它有所帮助.. !!