为什么我的复选框项目状态不会持久存在于Bootstrap模式中?

时间:2016-07-07 05:13:12

标签: javascript angularjs bootstrap-modal

我在Bootstrap Modal内有checkbox。当我检查它关闭模型时,如果我重新打开模态对话框,它就不会被检查。

我有一个名为$scope.price的列表,根据某些条件,该项目将来自该列表。如果我选择" The Washing"从下拉列表中,模态将打开,具有洗涤项目。以下是我的代码。

HTML

<div class="modal fade" id="Washing" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
        <div class="modal-header">
            <button type="button"  class="close" data-dismiss="modal">&times;</button>
        </div>
        <div class="modal-body">
            <table border="1">
            <tr ng-repeat="y in price">
            <td> {{ y.name }} </td>

            <td> {{ y.cost }} </td>
            <td> <input type="checkbox" value={{y.name}} ng-model="servicess[1].checked"> </td>
            </tr>
            </table>         
        </div>
        <div class="modal-footer">
            <button type="submit"  class="b1">Save</button>
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        </div>
        </div>
    </div>
</div> 

脚本

$scope.call = function(value)
{
    if(value=="washing")
    {
        $scope.price = [{
            "name": "Washing1",
            "cost": 500
            }, {
            "name": "Washing2",
            "cost": 600
            }, {
            "name": "Washing3",
            "cost": 700
        }];
    }
    else if(value=="wheel_align")
    {
        $scope.price = [{
            "name": "Wheel_Align1",
            "cost": 150
            }, {
            "name": "Wheel_Align2",
            "cost": 160
            }, {
            "name": "Wheel_Align3",
            "cost": 170
        }];
    }
    else if(value=="full_service")
    {
        $scope.price = [{
            "name": "full_service1",
            "cost": 15
            }, {
            "name": "Full Service2",
            "cost": 66
            }, {
            "name": "full_service3",
            "cost": 67
            }];
        }
};

$(".b1").on('click', function() {
    $('input[type=checkbox]').each(function(){
        if($(this).prop("checked") == true) {
            servicess.push($(this).val());
        }
        alert(servicess);
    }); 

    for(var i=0;i<servicess.length;i++)
    {
        $('input[type=checkbox][value='+servicess[i]+']').prop('checked',true);
    }
});

1 个答案:

答案 0 :(得分:0)

试试这个可能对你有帮助

$(".b1").on('click', function() { $('input[type=checkbox]').each(function(){ if($(this).prop("checked") == true) { servicess.push($(this).val()); } alert(servicess); }); 

$(&#39;输入[类型=复选框] [值=&#39 + servicess [I] +&#39;]&#39)。丙(&#39;检查&#39 ;,真正); });