【问题标题】:Display only the desired parameters仅显示所需参数
【发布时间】:2023-03-25 10:03:01
【问题描述】:

我在this tutorial 之后创建了一个应用程序(没有脚手架)。

创建项目后,我可以单击它,它会显示一个大参数列表。喜欢这里:http://s15.postimage.org/j6at9koiz/parameters.png

执行此操作的代码是:

<% if (todos && todos.length) { %>
  <% for (var i in todos) { %>
  <div class="row todo-item">
    <div class="span8">
        <h3><%- linkTo(todos[i].title, todoPath(todos[i].id)) %></h3>
    </div>
    <div class="span4"><h3><i class="icon-list-alt"></i><%= todos[i].status; %></h3></div>
  </div>
  <% } %>
<% } %>

更具体地说,以下行显示带有标题的链接,这些链接将我带到每个项目的参数列表:

<%- linkTo(todos[i].title, todoPath(todos[i].id)) %>

我可以做一些事情来只显示一些参数而不是现在显示的整个列表吗?

谢谢!

【问题讨论】:

    标签: node.js geddy


    【解决方案1】:

    您需要为待办事项资源添加视图文件。如果你正在搭建脚手架,那么 geddy 默认会创建它们。但除此之外,您必须在app/views/todos 中添加待办事项的视图文件。

    查看文件

    • _form.html.ejs
      • 编辑/新建表单
    • add.html.ejs
      • 新的资源视图
      • /todos/add
    • edit.html.ejs
      • 编辑视图
      • /todos/:id/edit
    • index.html.ejs
      • 索引视图
      • /todos
    • show.html.ejs
      • 显示单个资源
      • /todos/:id

    您可以手动编辑它们。要更改单个待办事项在 /todos/:id 路由上的显示方式,请编辑 show.html.ejs

    <div class="hero-unit">
      <%- linkTo('Edit this todo', editTodoPath(params.id), {class: 'btn pull-right'}); %>
      <h3>Params</h3>
      <ul>
        <li>todo.title</li>
        <li>todo.property1</li>
        <li>todo.property2</li>
      </ul>
    </div>
    

    【讨论】:

    • 如何只显示模型中定义的参数?
    • 所以没有什么可以自动执行此操作?...一个函数或仅返回模型字段或返回布尔值检查参数是否来自模型的东西?跨度>
    • 你的想法也不错,但我通过创建一个包含所需参数的数组然后检查当前参数是否在该数组中,如果是,则显示
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-02-04
    • 2023-02-15
    • 2012-08-10
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    相关资源
    最近更新 更多