Angular Access list Properties [closed] - angular12

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
In myI have cities withidandnameandcounteyidand countries withidandnamehow to iterate thisresponse.valueto get a list havingcityid,name,countryid`?

you can use map function I guess, here some example with your code. I extend your list like that and result shown below
const value = [
{
id: "1",
name: "cityname",
countryId: "countryId",
countries: [{ id: 1, name: "countryname" }],
},
{
id: "2",
name: "cityname-2",
countryId: "countryId-2",
countries: [{ id: 2, name: "countryname-2" }],
},
{
id: "3",
name: "cityname-3",
countryId: "countryId-3",
countries: [{ id: 3, name: "countryname-3" }],
},
];
// you can check your list result
console.log(
value.map((m) => ({
cityId: m.id,
cityName: m.name,
countryId: m.countryId,
}))
);

Related

Firebase security rules check multiple references

I am developing an application in which I need a set of users (employees) belonging to a group (store) to only be able to read from the "Customers" table if these customers have an order placed by an employee in the same store.
This is my structure thus far (top level are collections):
Users: [
{id: 1, name: "John", store: "a"},
{id: 2, name: "Jane", store: "a"},
{id: 3, name: "Charles", store: "b"},
],
Stores: [
{id: "a", name: "Store A"},
{id: "b", name: "Store B"},
],
Customers: [
{id: "1", name: "Customer 1", ...data},
{id: "2", name: "Customer 2", ...data}
],
Orders: [
{id: "001", customer: "/Customers/1", employee: "/Users/1"},
{id: "002", customer: "/Customers/2", employee: "/Users/3"}
]
In this example, John and Jane should be able to see the Customer 1 but not the Customer 2, and Charles should be able to see the Customer 2 but not the Customer 1.
I tried to make a function to do this, like so:
function canSeeCustomers() {
if get(/databases/$(database)/documents/users/$(request.auth.uid)).data.store == ?
}
But I don't know how to check the store field against the Orders collection.
Is there any way to do this? Or would I be better refactoring the DB structure to make Users a subdocument of Stores?
Add stores to your customers data too. stores: {a: true}.
So you could do
allow read: if resource.data.stores[get(/databases/$(database)/documents/users/$(request.auth.uid)).data.store];

How to use url: instead of data: for onExpandRow function?

I followed the example for onExpandRow, however I can't figure out how to use the row information that is passed with a url for my table instead of the data tag. Currently it just replicates my whole table in the expand function, not just the rows data. Probably a simple fix but I am missing it.
onExpandRow: function (index, row, $detail) {
console.log(row)
$detail.html('<table></table>').find('table').bootstrapTable({
url: 'table.php',
columns:[{
field: 'mfr_name',
title: 'manufacturer'},
{field: 'phone_number',
title: 'phone'},
],
})
The example has the data saved in a variable and uses the data: call instead of the url: one.
var data = [{
'col1': '1.1',
'col2': '1.2',
'nested': [{
'col3': '1.3',
'col4': '1.4',
'col5': '1.5'
}]
onExpandRow: function(index, row, $detail) {
console.log(row)
$detail.html('<table></table>').find('table').bootstrapTable({
clickToSelect: true,
columns: [{
field: 'select',
checkbox: true
}, {
field: 'col3',
title: 'Col3'
}, {
field: 'col4',
title: 'Col4'
}, {
field: 'col5',
title: 'Col5'
}],
data: row.nested,
Did you mean something like this:
http://jsfiddle.net/eitanmg/m41ok0ue/12/
The main change is when expanding the row, it will make AJAX call to get the data you want from remote resource and not from local variable.
$(function () {
$('#table').bootstrapTable({
data: data,
detailView:true,
onExpandRow: function (index, row, $detail) {
$detail.html('Loading request...');
$.ajax({
type: "GET",
url: "/your_custom_url_that_contains_the_data",
success: function (result) {
$detail.html('<table></table>').find('table').bootstrapTable({
columns: [{
field: 'select',
checkbox: true
}, {
field: 'col1',
title: 'Col1'
}, {
field: 'col2',
title: 'Col2'
}, {
field: 'col3',
title: 'Col3'
}],
data: JSON.parse(result),
});
}
});
}
});
});

Normalize different collections with a pre-flatted array a.k.a. joins

All normalizr examples are focused on nested objects they are expecting an API result that looks like this:
{
id: 1,
title: 'Some Article',
author: {
id: 1,
name: 'Dan'
}
}
But I actually found that the following format where you have to do the collections joins yourself is the one I'm dealing with the most, can I use normalizr to handle this case for me?
Posts [{ _id: 1, name: 'post text 1', userId: 5, locationId: 8}]
Locations [{ _id: 8, name: 'New York'}]
Users [{ _id: 5, name: 'John Doe', country: 'US'}]
expected result:
{
results: [1], // posts ids
entities: {
posts: {
1: { name: 'post text 1', userId: 5, locationId: 8 }
},
users: {
5: { name: 'John Doe', country: 'US' }
},
locations: {
8: { name: 'New York' },
}
}
}
Docs/github issues nothing mentions it as far as I could find

How do I use Normalizr to handle basic nested JSON?

I have a very standard nested JSON response. Projects have many dashboards. Dashboards have many charts.
What is the right way to define and use my schemas?
Below is the code for my Schemas.js, my API response, and what Normalizr converts my API response into.
Schemas.js:
import { Schema, arrayOf, normalize } from 'normalizr';
// Create a schema for each model.
const project = new Schema('projects');
const dashboard = new Schema('dashboard');
const chart = new Schema('chart');
// Projects have many dashboards.
project.define({
dashboards: arrayOf(dashboard)
});
// Dashboards have many charts.
dashboard.define({
charts: arrayOf(chart)
});
export const Schemas = { project, dashboard, chart };
My API response:
{
projects: [{
id: 1,
name: "Project 1",
dashboards: [{
id: 1,
name: "Dashboard 1",
charts: [{
id: 1,
name: "Chart 1"
},
{
id: 2,
name: "Chart 2"
}]
},
{
id: 2,
name: "Dashboard 2",
charts: [{
id: 3,
name: "Chart 3"
},
{
id: 4,
name: "Chart 4"
}]
}]
},
{
id: 2,
name: "Project 2",
dashboards: [{
id: 3,
name: "Dashboard",
charts: []
}]
}]
}
When I receive this JSON in an action I do normalize(response, Schemas.project);. This seems to move the entire response into entities.projects.undefined.
{
entities: {
projects: {
undefined: {
projects: [{
id: 1,
name: "Project 1",
...
}, ...]
}
}
},
result: undefined
}
How should I correctly define and use my schemas for this?
References:
https://github.com/gaearon/normalizr
https://github.com/reactjs/redux/blob/master/examples/real-world/actions/index.js
This should give you the desired result:
normalize(response, {
projects: arrayOf(Schemas.project)
});
The projects key is nescessary because you have an extra key in your response, and the arrayOf() indicates that the API returns an array of results.

how can i get Total like From A post in Facebook with Graph Api? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
how to get total likes a post from graph api url ?
Here This Link
Return:
array of objects containing the id and name fields. Requesting with summary=1 will also return a summary object containing the total_count of likes.
in the FB API explorer try fetching likes for a post, i used 700182169998352
the "/700182169998352/likes" return:
{
"data": [
{
"id": "663945278",
"name": "Irene Olsson Wikler"
},
{
"id": "100002437916716",
"name": "Frida Braxell"
},
{
"id": "1135121633",
"name": "Rex Leopold Olsson"
}
],
"paging": {
"cursors": {
"after": "MTEzNTEyMTYzMw==",
"before": "NjYzOTQ1Mjc4"
}
}
}
the "/700182169998352/likes?summary=1" return:
{
"data": [
{
"id": "663945278",
"name": "Irene Olsson Wikler"
},
{
"id": "100002437916716",
"name": "Frida Braxell"
},
{
"id": "1135121633",
"name": "Rex Leopold Olsson"
}
],
"paging": {
"cursors": {
"after": "MTEzNTEyMTYzMw==",
"before": "NjYzOTQ1Mjc4"
}
},
"summary": {
"total_count": 3
}
}
so by adding the ?summary=1 you get an extra part in the json result named summary,
and containng the total_count, in my case 3

Resources