【问题标题】:Sails.js error trying to edit and update functionSails.js 尝试编辑和更新函数时出错
【发布时间】:2017-12-07 18:16:43
【问题描述】:

我正在尝试使用 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

很抱歉将其发布为图片,我不知道该怎么办。

【问题讨论】:

    标签: javascript sails.js ejs


    【解决方案1】:

    您的代码似乎存在一些问题。

    如果您希望将编辑页面作为视图返回。以下步骤应该有效。

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

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

    res.redirect('/category');
    

    res.view({ category : data });
    

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

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

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

    【讨论】:

    • 现在我可以进入编辑页面,但是当我点击提交按钮时,我收到 Sending 500 server error response : ReferenceError: id is not defined。
    • 现在我明白了!谢谢!!但我还有更多问题,你能帮我解决这个问题吗?我在这里有点堆叠。
    • 他们是sails.js 相关的问题吗?
    • 是的,他们是。我现在被困了3个小时。还没有完成。
    • 您是否将它们作为堆栈溢出的新问题打开?
    猜你喜欢
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-01
    • 2018-07-17
    • 1970-01-01
    相关资源
    最近更新 更多