How to get the idRetainer in the listRetainerPaymentUnit? - angularjs

I have a Angualr JS application and i try to get Id on my JSON im new with JSON objects.
{{detAgent[queryFilter][0][listRetainerPaymentUnit][0]}}
{
"queryFilter": [{
"objPolicyData": {"idAssign": "219","idPromotoria": "JA",
"listStatusPolicy": [{"policyStatusCode": "V"}],
"collectionType": {"DxN": true},
"listRetainerPaymentUnit": [{"idRetainer": "100","nameRetainer": "RETAINER","idPaymentUnit": "109","namePaymentUnit": "PAYMEMT UNIT"}],
"listFederalEntity": [{"idFederalEntity": "MEX","nameFederalEntity": "CDMX"}],
"listZipCode": ""
},
"policyDataInfo": {
"policyNumber": "100",
"sizeOfFullPolicyDataObject": 480,
"unitSizeFullPolicyDataObject": "MB"
}
}]
}
I expect to obtain the data with a tag Id

Resolve i remove the ng-repeat directive in the html and to get the id I only pass the variable
<div class="col-3 text-left"><label>Id {{agentsDetailList.queryFilter[0].objPolicyData.idAssign}}</label></div>

Related

angularjs filter multidimensional object json

I wnt to use ng-repeat to display a list filtered by an object value. Here is a plukr of my attempt https://plnkr.co/edit/vD4UfzM4Qg7c0WGTeY18?p=preview
The following returns all of my JSON names as expected.
<li ng-repeat="item in collection_data">{{navitem.name}}</li>
now i want to filter and only show the names of the items that have "foreign_lang": "es", like in this json snippet
{
"id": "ddb06ba2-6348-4d45-9e63-a6fa3632e5c2",
"created_at": "2015-10-12T18:34:15.668Z",
"updated_at": "2016-04-14T15:55:37.433Z",
"custom_attributes": {
"Display Name": "Activos en EspaƱol",
"foreign_lang": "es",
"display_boxes": "false"
},
},
so i made this filter function
$scope.filterByDisplay = function() {
$filter('filter')($scope.collection_data, ['foreign_lang', 'es']);
}
and called it like this.
<li ng-repeat="item in collection_data" | filter: filterByDisplay>{{navitem.name}}</li>
I did not get any console errors but i got nothing returned.
How do I properly filter through this collection to only return items with 'foreign_lang', 'es' as a value in the json? See the plunkr to see a working example https://plnkr.co/edit/vD4UfzM4Qg7c0WGTeY18?p=preview
Third attempt (since the question was revised). Use the filter function to check each object individually, and returning only those that pass the truth test.
$scope.filterByDisplay = function(value) {
return (value.content)
&& (value.content.custom_attributes)
&& (value.content.custom_attributes.foreign_lang === "es");
}
Updated Plunk - Using Filter Function

how to iterate through an array and display it in $scope (angularjs)

Problem:
I am showing a list of documents in my application and one of the fields is a preview icon which shows a modal to display a pdf preview of the document. I am building a url to make it dynamic but I'm not sure how to iterate through the array
Controller:
$scope.documentIdentifier = documents.documentBag[0].documentId;
$scope.url = $sce.trustAsResourceUrl("http://localhost:3000/services/v1/" + $scope.documentId + "?type=pdf");
My object:
{
"documents": "Success",
"documentBag": [
{
"documentId": "E1DUPW9JPP1GUI3"
},
{
"documentId": "E1FUJW5JPP1GUI4"
},
{
"documentId": "G1DUJW3JPP1GUI5"
}
]
}
I need to iterate through the documentId to show all 3 documents but not exactly sure how.
Use ng-Repeat to iterate over the array and build your url.
$scope.documents = documents.documentBag;
$scope.url = $sce.trustAsResourceUrl("http://localhost:3000/services/v1/");
<div ng-repeat="document in documents">
{{url + document.documentId}}
</div>

Filtering on object properties not working

I'm trying to filter within an ng-repeat like this:
<li ng-repeat="file in files | filter: { values.filetype: 'Form' }">
If I change values.filetype: 'Form' to, say, id: 1, the filter works correctly. So how do I get it to work with the first property?
Edit: the structure of the data is like this:
{
"id": "3",
"values":
"title: "sldkfjsd",
"filetype": "Form"
}
This is solved with the following syntax:
filter: { values: { filetype: 'Form'} }

ng-repeat and nested array in json

i have some problems accessing some values stored in a json with the directive ng-repeat.
the json is formatted properly (checked it with a json checker) and it's called via $http service. unfortunately i can't change the format of json, retrieved through the wordpress-json-api plugin.
the json (with some cuts):
{
"status": "ok",
"count": 10,
"count_total": 24,
"pages": 3,
"posts": [
{
"id": 108,
"type": "sensor",
"slug": "ert",
"custom_fields": {
"sensor_id": [
"er"
],
"coords": [
"{\"address\":\"\",\"lat\":55.39979700000003,\"lng\":10.430533275390644,\"zoom\":12}"
]
}
}
//etc other posts following, json correct
Now i have a problem accessing the single values inside coords. i complained too about serializing data in db, but i'd like anyway to get lng and lat out of that array
<ul>
<li ng-repeat="post in sensor.posts">
<h4>name : {{post.id}}</h4> //ok
<h4>all custom fields : {{post.custom_fields}}</h4> //good-this-too
<h4>custom field lat : {{post.custom_fields.prova_coords[0]}}</h4> //works but can't go on
</li>
</ul>
the ouput of last line is:
custom field lat : {"address":"","lat":55.39979700000003,"lng":10.430533275390644,"zoom":12}
but now i'm stuck..can't retrieve single lat and long values
You need to use $scope.$eval(coordsString)
Here's a test: http://jsfiddle.net/mikeeconroy/Rnc7R/
var objString = "{\"address\":\"\",\"lat\":55.39979700000003,\"lng\":10.430533275390644,\"zoom\":12}";
$scope.coords = $scope.$eval(objString);
Then you can refer to coords.lat or coords.lng in your template like so:
<div ng-controller="myCoordsCtrl">
Lattitude: {{coords.lat}}<br>
Longitude: {{coords.lng}}
</div>
Since this is happening within an ngRepeat you may need to use an Angular filter to rectify the string on the fly
<li ng-repeat="post in sensor.posts | myRectifyCoordsFilter">
EDIT:
Don't use the filter like in the above example, using filters to modify $scope is not a good situation. You'll need to modify your $scope prior to using it in the ng-repeat
$http.get().success(function(data){
angular.forEach(data,function(val,key){
this.coords = $scope.$eval(val.coords[0]);
},data);
$scope.sensor = data;
});

display all items in an array of objects with each or jQuery .map()

I have an array of objects like this in a JSON:
[
{
"Name":"John Doe",
"Age":46,
"Hometown":"Anytown, USA",
},
{
"Name":"Jane Q. Public",
"Age":23,
"Hometown":"Mayberry, NC",
},
{
"Name":"Andrew Andrews",
"Age":62,
"Hometown":"New York, NY"
},
]
I need to convert it to HTML with this format:
<div class="person">
<h2>Name</h2>
<p class="name">John Doe</p>
<h2>Age</h2>
<p class="age">46</p>
<h2>Hometown</h2>
<p class="hometown">Anytown, USA</p>
</div>
...
Would it be best to use jQuery's .map() for this? Or each ? How should I set it up?
I was able to do this with the loadJSON plugin, which is very handy in creating an HTML template from actual HTML. I'd still be interested in a .map() or each way to do it.

Resources