【问题标题】:Cannot check jquery ui checkbox based on values from angularjs model无法根据来自 angularjs 模型的值检查 jquery ui 复选框
【发布时间】:2017-01-06 09:48:06
【问题描述】:

我正在使用 jQueryui checkbox group 向用户显示三个选项。我成功地将这些复选框中的每一个绑定到一个角度模型,但是如果我更改控制器中的模型,我无法让这些复选框自行检查。

查看

<body ng-controller="MainCtrl">
<div id="groupOptions">
<label><input type="checkbox" name="test1" ng-model="testModel.item1" ng-checked="testModel.item1" /> Testing</label>
<label><input type="checkbox" name="test2" ng-model="testModel.item2" ng-checked="testModel.item2" /> Testing 2</label>
<label><input type="checkbox" name="test3" ng-model="testModel.item3" ng-checked="testModel.item3" /> Testing 3</label>
</div>
<pre>{{testModel|json}}</pre>
<script>
    $("#groupOptions").controlgroup();
</script>

角度模块

var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
  $scope.testModel = {
    item1: true,
    item2: false,
    item3: false
  };
});

请注意 testModel.item1 为真,但未选中此模型绑定的复选框 test1。
这是Plunker link

我也尝试过用 check="testModel.item1" 代替 ng-checked="testModel.item1" ,无论模型/控制器中的值是什么,它都会选中所有复选框。

我错过了什么?

谢谢

【问题讨论】:

    标签: jquery angularjs


    【解决方案1】:

    你缺少 jquery $(document).ready

    $(document).ready(function(){
        $("#groupOptions").controlgroup();
    });
    

    【讨论】:

    • 这解决了我的问题。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 2012-01-09
    • 1970-01-01
    • 2013-03-09
    • 1970-01-01
    相关资源
    最近更新 更多