0
I've a boolean field in the model just similar to the below one. And I want to create a view using embedded javascript.   
**settings.js**

module.exports = {

   attributes: {
       myField:{
          type:'boolean',
          defaultsTo:'false'
       }
   }
};

这是我正在使用的代码

 <form action="/settings/create" method="POST" id="sign-up-form" class="form-inline">

     <div class="form-group">
     <label for="field1">my field label</label>
      <input type="checkbox" class="form-control" id="field1" name="myField">
    </div>

    <input type="submit" class="btn btn-primary" value="Create"/>
    <input type="hidden" name="_csrf" value="<%= _csrf %>" />
</form>

所以我面临的问题是

  1. 当我创建记录时,我可以看到布尔值在 json 中设置为ONOFF,为什么这不是true 或 false
  2. 以及如何使用嵌入式javascript在视图中呈现真或假
4

1 回答 1

0
  <div class="form-group">
    <label for="confirmationBox">Field Label</label>
    <% if(object.fieldName==true || object.fieldName=="true"){ %>
    <input type="checkbox" id="confirmationBox" name="confirmationBox" checked>
    <% } else { %>
    <input type="checkbox" id="confirmationBox" name="confirmationBox">
    <% } %>
  </div>
于 2015-10-03T19:12:59.237 回答