How to apply filter in Angular - javascript

I am new to Angular and would like to apply filter to this JSON to only get "place" objects.
{
"places": {
"live": "true",
"status": "default",
"place": [
{
"-name": "Test",
"-url": "http://myurl"
},
{
"-name": "Test",
"-url": "http://myurl"
},
{
"-name": "Test",
"-url": "http://myurl"
}
]
}
}
I was thinking of applying filter with something like this:
<div ng-repeat="place in places | filter:{place:'http'}">
This is clearly wrong . Is there a way to apply filter to only get "place" objects

<div ng-repeat="place in places.place">
should work I think

Related

How to delete a paticular Object in an array inRethinkDB

I am Just trying to learn RethinkDB.I am little Bit Confused That how to delete an single Object in an array,What is the Exact query I have to use if i have to delete this Object
{
"name": "Ram" ,
"username": "B97bf210-c4d2d-11e6-b783-07b5fev048705"
}
from whoLikedIt Array
My data
{
"comments": [ ],
"id": "c242c74d-03d9-4963-9a22-4779facb8192" ,
.....
"views": 0 ,
"whoLikedIt": [
{
"name": "Vignesh Warar" ,
"username": "d97bf210-c42d-11e6-b783-07b5fe048705"
},
{
"name": "Ram" ,
"username": "B97bf210-c4d2d-11e6-b783-07b5fev048705"
},
]
.....
}
My Try
r.db('image').table('posts').get('c242c74d-03d9-4963-9a22-4779facb8192').update(
{whoLikedIt:r.row('whoLikedIt').filter({username:"B97bf210-c4d2d-11e6-b783-07b5fev048705"}).delete()}
)
Throws Me a error
e: Cannot nest writes or meta ops in stream operations. Use FOR_EACH instead in:
You want:
r.db('image').table('posts').get('c242c74d-03d9-4963-9a22-4779facb8192').update(function(row) {
return {whoLikedIt: row('whoLikedIt').filter(function(obj) {
return obj('username').ne("B97bf210-c4d2d-11e6-b783-07b5fev048705");
})};
})

How to do ng-repeat on $firebaseArray output with multiple levels?

I am using $firebaseArray for collecting the data from Firebase. Output is as follows:
[
{
"BankAccount": {
"AccountHolder": "Tom Antony",
"AccountNumber": "56767887"
},
"Info": {
"BillingAddress": {
"City": "XYZ",
"State": "ABC"
},
"FullName": "Tom Antony",
"PhoneNumber": "634762347"
},
"$id": "dGUZX5SWi7aP0SNYLYqEiMdCYAS2",
"$priority": null
},
{
"Campaigns": {
"Settings": {
"Active": true
}
}
},
"Info": {
"BillingAddress": {
"City": "ABC",
"State": "DFG"
},
"FullName": "Mario",
"PhoneNumber": "634762347"
},
"$id": "tBqGZ7g6VwNYOWoVy7C1FHKZKFS2",
"$priority": null
}
]
My js is as follows:
const rootRef = firebase.database().ref().child('Users');
$scope.users = $firebaseArray(rootRef);
Each Array element will have different type of objects, but each will have a similar object called Info, which contains a field for FullName I need to apply ng-repeat on this FullName. My implementation is as shown below:
<div ng-repeat="user in users.Info">
<p ng-bind="user.FullName"></p>
</div>
But its not working. What are the mistakes I made here?
You are trying to iterate on the wrong property. You have two objects (user) which each have an Info property that you want the FullName from. You do not have two Info objects. Therefore, you should be iterating over the users, not iterating over users.Info.
Try this instead:
<div ng-repeat="user in users">
<p ng-bind="user.Info.FullName"></p>
</div>
Also, your object you pasted here wasn't valid JSON, you had an extra }.
Full Working example: http://plnkr.co/edit/ryfjhO0c3egHfKnaL9SQ?p=preview

AngularJS deep filter through array in ng-repeat

My question is looking similar to other questions. But it is different.
Please take a look of below code.
I want to filter data by an array of objects.
Here is the snippet
HTML
<div
ng-repeat="(key, value) in ledgerData.ledgers track by $index"
ledger-pop
index="$index"
ftype="ftypeUpdate"
itemdata="value"
acntlist="fltAccntList"
class='drEntryForm_{{$index}} pr'
name='drEntryForm_{{$index}}'
update-ledger="updateEntry(entry)"
novalidate
>
</div>
JS
$scope.ledgerDataata = {
"ForwardedBalance": {
"amount": 0,
"type": "CREDIT"
},
"creditTotal": 4008,
"debitTotal": 4008,
"balance": {
"amount": 4008,
"type": "CREDIT"
},
"ledgers": [
{
"transactions": [
{
"particular": {
"name": "Sarfaraz",
"uniqueName": "temp"
},
"amount": 1001,
"type": "DEBIT"
}
],
"description": "testing",
"tag": "testing"
},
{
"transactions": [
{
"particular": {
"name": "frnd",
"uniqueName": "frndafafaf14453422453110l26ow"
},
"amount": 2001,
"type": "CREDIT"
},
{
"particular": {
"name": "Rahul",
"uniqueName": "cake"
},
"amount": 3001,
"type": "DEBIT"
}
],
"description": "testing",
"tag": "testing",
}
]
}
I am trying to filter by
ng-repeat="(key, value) in ledgerData.ledgers track by $index | filter:{transactions[0]:{type: 'DEBIT'}}"
But am getting error
thanks in advance :-)
You need to write nested ng-repeat to solve this problem.
outer ng-repeat for the array ledgerData.ledgers and
inner ng-repeat for transaction array in ledgerData.ledgers
<div ng-repeat="(keyOne, ledger) in ledgerData.ledgers track by $index">
{{ledger.description}}
<div ng-repeat="(keyTwo, transaction) in ledger.transactions | filter:{type:'DEBIT'}">
{{transaction.type}}
</div>
</div>
Actually I got the solution.
I've googled hardly and got a library for angularjs-filter.
Here is the link it is very good plugin for filter dirty works and how to use it.
How I got success:
html
ng-repeat="(key, value) in ledgerData.ledgers | pick: debitOnly track by $index"
AngularJS
$scope.debitOnly = (ledger) ->
'DEBIT' == ledger.transactions[0].type
that's it.

json-schema v4 how-to implements enums depending on enums?

Using json-editor, and looking at this answer, I am trying to do the following, using json-schema v4:
Use a root property to select one of two categories ['clothing', 'accessory'], which will determine enum-values for a material property.
The case I am trying to solve has multiple enum-properties depending on the category-value.
Pseudocode example:
{
"type": "object",
"Title": "Products",
"definitions": {
"clothing": {
"materials": ["yak", "merino"]
},
"accessories": {
"materials": ["brass", "silver"]
}
},
"properties": {
"productType": {
"type": "string",
"enum": [
"clothing",
"accessories"
]
},
"materials": {
"type": "array",
"title": "Materials",
"items": {
"type": "string",
"title": "Material",
"enum": [
{"$ref" : "#definitions/{{productType}}/materials"}
]
}
}
}
}
Any suggestions on how to structure this?
In this case it might be easier to define types for the first level with a oneOf clause, and use enums just in the nested level. Something like:
"definitions" : {
"materialType" : {
"oneOf" : [{
"$ref" : "#definitions/clothing"
}, {
"$ref" : "#definitions/accesories"
}
]
},
"clothing" : {
"materials" : {
"enum" : ["yak", "merino"]
}
},
"accessories" : {
"materials" : ["enum" : ["brass", "silver"]]
}
}
Then you consume materialType like this:
"materials": {"$ref":"#definitions/materialType"}
If you want also to encode the materialType within the object instance, then you may add another property enum like this, but I would not recommend this:
"clothing" : {
"materials" : {
"enum" : ["yak", "merino"]
},
"kind": {"enum" : ["clothing"]}
}

ng-repeat not pushing data

I'm using ng-repeat directive to list a set of JSON data of the format
$scope.result=[
{
"id": 84,
"resource": {
"id": 3,
"name": "Resource Planning",
"description": "test"
},
"activity": {
"id": 6,
"name": "Activity Planning",
"description": "test"
}
}
]
My usage of ng-repeat is like this..
<div ng-repet="data in result">{{data.resource.name}} {{data.activity.name}}</div>
I'm able to display the name ie., "Resouce Planning" and "Activity Planning".
But I can't push the data if I'm doing like this
$scope.result.push({resource.name:result.resource.name,activity.name:result.activity.name})
from the controller.
Is there any way to push the name which is inside the object. And to display/list the same using ng-repeat?
Thanks
I don't really understand the question, but that's not how you build your javascript object. It should be something like:
$scope.result.push({
resource: {
name: result.resource.name
},
activity: {
name: result.activity.name
}
})

Categories