【问题标题】:Get checkboxes to send value instead of boolean获取复选框以发送值而不是布尔值
【发布时间】:2016-06-01 16:15:22
【问题描述】:

我有带有 HTML 值的复选框。问题是我希望将值存储在数据库中而不是布尔值。我该怎么做?

HTML:

 <div class="form-group" >
    <label >Bachelor</label><br>

        <input type="checkbox" id="ComputerScienceB" ng-model="vm.course.bachelor.computer" value="Computer Science"> Computer Science
        <br>
            <input type="checkbox" id="SystemsEngineeringB" ng-model="vm.course.bachelor.systems" value="Systems Engineering"> Systems Engineering
        <br>
        <input type="checkbox" id="EnvironmentalEngineeringB" ng-model="vm.course.bachelor.environmental" value="Environmental Engineering"> Environmental Engineering
           <br>
            <input type="checkbox" id="MechanicalEngineeringB" ng-model="vm.course.bachelor.mechanical" value="Mechanical Engineering"> Mechanical Engineering
        <br>
            <input type="checkbox" id="BiotechnologyB" ng-model="vm.course.bachelor.bio" value="Biotechnology"> Biotechnology
    </div>
    <br>


    <div class="form-group">
        <button type="submit" class="btn btn-primary" ng-click="vm.saveCourse()">Add Course</button>
    </div>
</form>

数据库插入坑vm.course。我正在使用孔均值堆栈。

【问题讨论】:

  • 你可以使用ng-true-value="some"

标签: html angularjs checkbox mean-stack


【解决方案1】:

您需要ng-true-value 属性。你可以这样使用它:

<input ng-true-value="Biotechnology"
  type="checkbox"
  id="BiotechnologyB"
  ng-model="vm.course.bachelor.bio">

见angular docs on input[checkbox]

【讨论】:

    猜你喜欢
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 2020-06-14
    • 2017-11-11
    • 2016-12-10
    • 2015-02-05
    • 2014-02-05
    • 1970-01-01
    相关资源
    最近更新 更多