mardi 22 mars 2016

How to Filter with checkboxes in angularjs for json values?

I am trying to display my json values on UI using angularjs/coffeescript based on my checkbox filters selection. I have tried the following, but my values(test1, test2, test3) are coming/displaying by default on my application execution on my view page, that's fine(i.e on without any checkbox selection). But If I select any checkbox then it is not filtering the respective values to display the selected checkbox related values on view page(Like if I select Test1 checkbox then test1 value should be displayed on page, but nothing is happening), I am not sure where and what I am doing wrong to filter the respective values ? Please help me and thanks in advance.

in my coffeescript:

@testValues = []
@testData = []
#my application code goes here
alert testValues #gives all my actual values(like: test1,test2,test3)
alert testData #gives [object Object]

html:

<html>
<body>
<div ng-controller="Testapp as testapp"> 
<input type="checkbox" data-ng-model='testapp.testValues.description' data-ng-true-value='test1' data-ng-false-value='' /> Test1 &nbsp;&nbsp;&nbsp;
<input type="checkbox" data-ng-model='testapp.testValues.description' data-ng-true-value='test2' data-ng-false-value='' /> Test2 &nbsp;&nbsp;&nbsp;
<input type="checkbox" data-ng-model='testapp.testValues.description' data-ng-true-value='test3' data-ng-false-value='' /> Test3
<table>
<tbody>
  <tr  ng-repeat="testName in testapp.testValues | filter:testapp.testValues.description">
     <td>{{ testapp.testData[testName].description }}</td>  //giving test1, test2, test3
   <tr>
</tbody>
</table>   
</body>
</div>
</html>

json:

{                       
"jsontestvalues": {
        "First": {
            "description": "test1",
            },
        "Second": {
            "description": "test2",
            },  
        "Third": {
            "description": "test3",
            }
}
}   




Aucun commentaire:

Enregistrer un commentaire