在angularjs中的数据bindnig之后检查显示复选框 [英] Show checkboxes checked after data bindnig in angularjs

查看:73
本文介绍了在angularjs中的数据bindnig之后检查显示复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想在下拉列表html控件中显示复选框。我使用angularjs绑定数据。

这种类型的控件在html中不可用。所以我创建了一个div并应用了样式,使其看起来像下拉列表。

使用ng-repeat,我可以在其中创建复选框。

当用户选中一个复选框时,按钮点击将其文本存储在数据库中。



我想要它,当页面加载时,相应的复选框应该检查我们存储在数据库中的值。



这是HTML:

Hi,
I want to show checkboxes in a dropdown html control. I am binding data using angularjs.
This type of control is not available in html. So I have created a div and applied styling to it to look like a dropdown.
Using ng-repeat, I am able to create checkboxes inside it.
When a user checks a checkbox, its text is stored in database on button click.

What I want it, when page loads, the respective checkboxes should get checked whose values we stored in database.

Here is the HTML:

<dl class="dropdown"> 
  <dt>
      <a href="#">
	<span class="hida">Select</span>    
	<p class="multiSel"></p>  
      </a>
  </dt>
  <dd>
      <div class="mutliSelect">
	<ul>
	   <li class="floatLeft widthFull" data-ng-repeat="code in MultipleRhythm">
		<label class="floatLeft"> <input type="checkbox" class="floatLeft multiCheckbox" value="{{code.Name}}" />{{code.Name}}</label> 
	   </li>
        </ul>
      </div>
   </dd>	
</dl>





这是js:



Here is js:

$scope.MultipleRhythm = $scope.ManagerCollection["Multiple Rhythm"]["Multiple Rhythm"];



这给了我一个循环使用ng-repeat的集合


This gives me a collection to loop through using ng-repeat

$scope.SelectedMultipleRhythm = $filter('GetMultiSelectedOptions')($scope.MultipleRhythm, $scope.ManagerCollection["SelectedMultipleRhythm"]);



这给出了用户选择的来自db的值。这是逗号分隔。



如果用户选择了3个值,我想要显示这三个复选框。



我尝试了什么:



我尝试使用ng-if,ng检查了如果code.Name == SelectedMultipleRhythm,则显示复选框已选中。但没有运气。


This gives values selected by user which come from db. This is comma separated.

If user has selected 3 values, I want to show those three checkboxes checked.

What I have tried:

I tried using ng-if, ng checked that if the code.Name == SelectedMultipleRhythm, then show checkbox checked. But no luck.

推荐答案

scope.MultipleRhythm =
scope.MultipleRhythm =


scope.ManagerCollection [ 多个节奏] [ Multiple Rhythm];
scope.ManagerCollection["Multiple Rhythm"]["Multiple Rhythm"];



这给了我一个循环使用ng-repeat的集合


This gives me a collection to loop through using ng-repeat


scope.SelectedMultipleRhythm =
scope.SelectedMultipleRhythm =


这篇关于在angularjs中的数据bindnig之后检查显示复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆