angularjs checkbox双向绑定

1.首先有这样一个对象,这个对象我不知道里面具体的属性和属性值,使用checkbox如何实现双向绑定?

{
"title":true,
"tel":false,
"price":true,
"info":true
}

1>html

<div class="padding-tb-10">
                <label >分词字段:</label>
                <span class="label label-default">所有字段</span>
                    <label class="checkbox-inline" ng-repeat="(key, value) in segmentColumn">
                        <input type="checkbox" name="segmentType" ng-model="segmentColumn[key]"   ng-true-value="true" ng-false-value="false"  > {{key}}
                    </label>
            </div>
2>controller

$scope.segmentColumn={
	"title":false,
	"tel":true,
	"price":true,
	"info":true
}
3>页面


2.radio双向绑定 没什么可说的

 
<label class="checkbox-inline">
    <input type="radio" name="segmentType" ng-model="analysisProject.segmentType"     value="BaseAnalysis"  > 基本分词
</label>
<label class="checkbox-inline">
    <input type="radio" name="segmentType" ng-model="analysisProject.segmentType" value="ToAnalysis" > 精准分词
</label>
<label class="checkbox-inline">
    <input type="radio" name="segmentType" ng-model="analysisProject.segmentType" value="NlpAnalysis" > nlp分词
</label>
<label class="checkbox-inline">
    <input type="radio" name="segmentType" ng-model="analysisProject.segmentType" value="IndexAnalysis" > 面向索引分词
</label>

今天发现在ng-repeat下并不能成功获取绑定值。

ng-repeat会在上一级作用域名中创建一个子 作用域。

此时如果需要在子作用域中调用父作用域的变量,则可以使用$parent.variableName来调用。


<label class="checkbox-inline" ng-repeat="dic in dictionaries">

    <input type="radio" name="dictionaryId" value={{dic.id}} ng-model="$parent.dictionaryId"  />{{dic.id}} {{dic.name}}

</label>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值