Sails.js 尝试编辑和更新函数时出错

Sails.js error trying to edit and update function

我正在尝试使用 Sails.js 创建编辑功能和更新功能,但在我点击编辑按钮后出现错误。

<html>
    <body>
    <table>
    <thead>
    <th>id</th>
    <th>name</th>
    </thead>
    <tbody>
    <% for(var i=0; i<categories.length; i++){ %>
    <tr>
    <td> <%= categories[i].id %> </td>
    <td> <%= categories[i].name %> </td>
    </tr>
    <a href="category/edit?id=<%= categories[i].id %>">Edit</a> //when click on this it should be appeared to edit page. but instead I got an error
    <% } %>
    </tbody>
    </table>
</body>
    </html>

this is my controller

this is my edit page

this is routes

this is the error that i got

不好意思把它post当成图片了,我不知道怎么办。

您的代码似乎有几个问题。

如果您希望 return 您的编辑页面作为一个视图。以下步骤应该有效。

首先,从路由配置文件中删除所有对 /category/edit 路由的引用。

然后更改您的 CategoryController 中的编辑功能以响应视图并将来自 findOne 模型方法的数据传递到响应中。为此替换

res.redirect('/category');

res.view({ category : data });

最后,更改类别编辑视图以使用响应中传递的数据。

action="/category/update/<%= category.id %>"

有任何问题,请在评论中告诉我。