How can I get only the data array from the observable response ?, I need to get the values of cat_id,cat_name,cat_description but not the sql_types array
{
"code": 0,
"message": "",
"data": [
{
"cat_name": "Topografía",
"cat_description": "Servicios de topografía en general",
"cat_id": 1
},
{
"cat_name": "Estructuras hormigón",
"cat_description": "subcontratas de estructuras de hormigón ",
"cat_id": 3
}
],
"sqlTypes": {
"cat_name": 12,
"cat_description": 12,
"cat_id": 4
}
}
You can pipe your observable and map it to the object you want.
Only your data will be availible in the example below
Observable.pipe(map(resp => resp.data)).subscribe(data=> //do something)
Related
I have following problem: I try to get the values of "place" with ngfor.
Following i use:
.html
<ng-container *ngFor="let se of List"
Following Json:
.json
"place": [
{
"id": 1,
"name": "Ort",
"number": "Nummer",
"type": "Art",
"height": 20,
"width": 42,
"lagerin": [
{
"id": 1,
"secnname": "Regal ",
"secnnumber": "R1",
"sectype": {
"sectypename": "Big ",
"ro": 5,
"co": 2,
"secheight": 20,
"secwidth": 6,
"secdepth": 1,
"sectco": 1
}
},
{
"id": 2,
"secnname": "Reg 2 ",
"secnnumber": "R2",
"sectype": {
"sectypename": "Small",
"ro": 3,
"co": 3,
"secheight": 25,
"secwidth": 4,
"secdepth": 2,
"sectco": 2
}
}
]
}
]
I get the error above. So my idea is to get the attributes in "place" to use them in my code.
It was working fine, before i add "lagerin". But i need this one in "place".
.ts
ngOnInit() {
this.route.queryParams
.subscribe(params => {
this.id = params.id;
});
if (this.id) {
this.service.gelager(this.id).subscribe(data => {
if (data) {
this.List= data;
} else {
console.log('No lager available');
}
});
}
}
If your getLager method returns the Json you showed us then you should have
this.list = data.place
And your local variables should not start with a capital letter, it is just a convention
AngularJS Service:
Get json sub-record field for import into current open array record.
I have one json file with "services" in it (id, name) services.json,
I need to forEach through them, but as I am in each service I need to open sub-record(welding.json) and grab a field(title) and add it to the current record.
NOTE: My project is a CLI type.
services.json
[
{
"id": 1,
"name": "welding"
},
{
"id": 2,
"name": "carpentry"
},
{
"id": 3,
"name": "mechanic"
}
]
= Sub-Records =
welding.json
{
"category": "labor",
"title": "Arc Welding",
"description": "",
"experience": "20+ Years",
"details": ""
}
Expectation:
{
"id": 1,
"name": "welding",
"title": "Arc Welding"
}
Try this
angular.forEach($scope.services, function (value, key) {
if(value.name == 'welding'){
$http.get('welding.json').then(function (response) {
$scope.welding = response;
})
$scope.services.title=$scope.welding.title;
}});
How can i access subjects in Json response and take the value which in types using typescript ?
Json Response :
{
"$id": "1",
"Council_ID": 102,
"place": "bla bla bla",
"number": "4644",
"type": 2,
"user_Id": 15,
"subjects": [
{
"$id": "2",
"subjectCode": "464",
"type": 1,
"branch": "cairo",
"gender": true
},
{
"$id": "3",
"subjectCode": "466",
"type": 5,
"branch": "alex",
"gender": true
}
],
"absence": []
}
meeting.component.ts :
this.dataStorageService.getCouncilId(this.meetingID).subscribe(response => {
this.subjectsWithID = response.json();
console.log(this.subjectsWithID, 'All Response')
this.typee = this.subjectsWithID.subjects.type;
console.log(this.typee, 'bla bla');
});
Here is how to access the values
this.subjectsWithID.Council_ID; // 102
this.subjectsWithID.type; // 2
this.subjectsWithID.$id; // '1'
this.subjectsWithID.subjects[0].$id; // '2'
this.subjectsWithID.subjects[0].type; // 1
this.subjectsWithID.subjects[1].$id; // '3'
this.subjectsWithID.subjects[1].type; // 5
I might have misunderstood your question. If so please provide some example of the desired output.
this.dataStorageService
.getCouncilId(this.meetingID)
.map(json)
.map(response => response.subjects.map(subject => subject.type))
.subscribe(response => { ... });
I'm trying to receive a json array from an api and display it on page, i'm fairly certain that something is wrong with my service, i just don't know what.
getAuctions(): Promise<Auction[]> {
return this.http.get(this.auctionsUrl)
.toPromise()
.then(response => response.json().array as Auction[])
.catch(this.handleError);
}
here is a response example
[
{
"id": 1,
"name": "Antik stol",
"description": "En fin antik stol från 1800-talet",
"startTime": "2016-12-13T10:00:00",
"endTime": "2017-02-23T10:00:00",
"imageUrl": "https://thumbs.dreamstime.com/z/antik-stol-som-stoppas-i-sammet-32935346.jpg",
"categoryId": 1,
"supplierId": 2,
"buyNowPrice": 8000,
"sold": true
},
{
"id": 2,
"name": "Antikt bord",
"description": "En fint antikt bord",
"startTime": "2016-12-10T10:00:00",
"endTime": "2017-03-29T10:00:00",
"imageUrl": "http://precisensan.com/antikforum/attachment.php?attachmentid=78277&stc=1&d=1292057973",
"categoryId": 1,
"supplierId": 1,
"buyNowPrice": 18000,
"sold": false
}
]
AuctionService:
getAuctions() : Observable<Auction[]> {
return this.http.get(this.auctionsUrl)
.map((response: Response) => response.json())
.catch(this.handleError)
}
AuctionComponent:
getAuctions(): void {
this.auctionService.getAuctions()
.subscribe(auctions => this.auctions = auctions);
}
For a given JSON how do I get the _id to use it as an id for inserting in another JSON?
Tried to get the ID as shown below but does not return correct results.
private def getModelRunId(): List[String] = {
val resultsCursor: List[DBObject] =
modelRunResultsCollection.find(MongoDBObject.empty, MongoDBObject(FIELD_ID -> 1)).toList
println("resultsCursor >>>>>>>>>>>>>>>>>> " + resultsCursor)
resultsCursor.map(x => (Json.parse(x.toString()) \ FIELD_ID).asOpt[String]).flatten
}
{
"_id": ObjectId("5269723bd516ec3a69f3639e"),
"modelRunId": ObjectId("5269723ad516ec3a69f3639d"),
"results": [
{
"ClaimId": "526971f5b5b8b9148404623a",
"pricingResult": {
"TxId": 0,
"ClaimId": "Large_Batch_1",
"Errors": [
],
"Disposition": [
{
"GroupId": 1,
"PriceAmt": 20,
"Status": "Priced Successfully",
"ReasonCode": 0,
"Reason": "RmbModel(PAM_DC_1):ProgramNode(Validation CPG):ServiceGroupNode(Medical Services):RmbTerm(RT)",
"PricingMethodologyId": 2,
"Lines": [
{
"Id": 1
}
]
}
]
}
},
If you want to find objectId's:
import com.mongodb.casbah.Imports._
collection.find(MongoDBObject(/*query*/)).map(_._id)
If you want to query by id:
collection.findOneByID(/*id*/)
I suppose you are using Casbah, the official Driver for Scala.
You just need to modify the map function :
resultsCursor.map { x => x.as[org.bson.types.ObjectId](FIELD_ID)}
Casbah does the deserialization from BSON to Scala object, so you don't have to do it yourself !