How do I structure blog posts/comments in HTML so that I can select them later on using jQuery/Javascript for updating/deleting/Ajax calls?
My instinct is to use those posts'/comments' IDs (primary key in the database) as their id= attributes in HTML e.g.
<section class="posts">
<div id=**post's ID (primary key) here**> post </div>
</section>
Is this a bad thing? (exposing details to the web such as primary keys, etc) or not necessarily?
I don't see a problem with that. Assuming your server returns a list of entities in JSON:
{
"comments": [
{ "id": "001", "author": "Jack", "comment": "Hello" },
{ "id": "002", "author": "Jill", "comment": "there" }
],
"posts": [
{ "id": "003", "author": "Greg", "comment": "This is an awesome website." },
]
}
You could use the id property of each to store it in the HTML for later retrieval:
<div id='001'>Hello</div>
<div id='002'>there</div>
Remember HTML ids are global across the entire page, so your ids across comments, posts, and any other entities present on the page must be unique. It might be a good idea to prefix them to avoid collisions, like comment001, comment002, post001, etc.
This is essentially what other frameworks do (like React) behind the scenes.
Related
Does Prisma have the ability to move nested fields from another table join to the top level of the result, like a flattened view? I want to put the result JSON into a frontend table without digging through nested objects and building another object.
For example I want to replicate this behavior where I can pick and choose the columns from different tables (columns from User, and School). Currently I use a raw query with a similar SQL, however I wonder if it's possible with using only the Prisma API:
SELECT
u.id
, u.email
, s.school_name
FROM "User" AS u
JOIN "UserSchool" AS us ON us.user_id = u.id
JOIN "School" AS s ON s.id = us.school_id
id | email | school_name
123| student1#email.com | mount high
I want JSON that looks like this:
{
"id": "1",
"email": "student1#email.com",
"school_name": "mount high",
}
If I did this in Prisma, I would need to go into several levels of nested objects to get the same column name on another table for e.g. user[user_school][schoo][school_name]. This requires extra work to loop through all my results, extract from the nested object, and build another object. This example isn't too bad, but I have more joins and deeply nested objects for my actual problem (lots of association/lookup tables). I've experimented with the select and include for my joins, but they are structured with the nested JSON.
users = await prisma.user.findMany({
include: {
user_school: {
include: {
school: true,
},
},
},
{
"id": "1",
"email": "student1#email.com",
"user_school": [
{
"id": 1,
"user_id": "1",
"school_id": "1",
"school": {
"id": 1,
"school_name": "mountain high",
}
}
],
}
It's not possible to flatten out the results as of now.
The only way to achieve this would be by using rawQuery as you mentioned.
However, there is an existing Feature Request which discusses Flattening out the results by providing an option of flatten:true. If you could mention your use case there and add a comment it would help Prisma's Product and engineering team in prioritising it.
I'm working on a ticket system, and I want to make a close ticket system, that will remove the ticket from the user, so I have my mongo array looking like this
{
"tickets": [{
"id": "cxZgqey2",
"subject": "fdgfdgdfgfdgfd",
"message": "gfdgfdgfdgdfg",
"ownerEmail": "soenmtherhg#gmail.com"
},
{
"id": "r4r-CnIC",
"subject": "dfdsfdsfsdfdsfdsf",
"message": "dsfdsfdfsdfdsfdsfdsfdsf",
"ownerEmail": "soenmtherhg#gmail.com"
}
]}
and I wanted to remove the entire object using only the id, how would I do this? (Using the npm module (not mongoose))
You can use the filter function in arrays and delete it passing the relevant id for that and also you can check loadash.
I am prototyping a Food Ordering app using Dialogflow(Chatbot maker) and got stuck with this problem. Technically, I want to persist the gathered data from an Intent after the user decided to "add more items to their order" and satisfies all the required parameters, which are, (itemName, quantity, [variants], [sauceType], ...).
The chat bot should be able to handle a request which consist of multiple items with their corresponding quantities but I am not sure if it's possible to model a data wherein it consist an array of Entities so, my first thought was to use a persistent Fulfillment using session-based Webhook with our custom Web Service, like for example: foodorder/api/order/123/items/add and 123 being the Session Id. But this approach requires more work and the generated model can be difficult to translate in Dialoflow Console.
The second solution comes into my mind, is to leverage the Intent property called Action and Parameters where we mark the Entity as List, but using this approach, the quantity doesn't get attached to the item itself.
My question is, how can I be able to model a data using Dialogflow that resembles something like below:
{
"givenName": "Dummy User",
"order": [
{
"itemName": "Burger",
"quantity": 2
},
{
"itemName": "6 piece Chicken Nuggets",
"quantity": 1,
"sauceType": "Tangy Barbeque"
},
{
"itemName": "Coke",
"quantity": 1,
"size": "Small"
}
]
}
Turns out what I was looking for was Composite Entities and mark it as a list.
The detailed answer can be found on this link:
https://stackoverflow.com/a/47166123/2304737
I'm currently working on a recursive menu which is built on top of jQuery which looks quite good already.
The structure of the JSon file containing the menu looks as the following:
[
{
"Id": "menuOfficeWebControlsForWebApplication",
"Title": "Office Web Controls",
"Resource": "/Documentation/Data/index.html" },
{
"Id": "menuGettingStarted",
"Title": "Getting Started",
"Resource": "/Documentation/Data/getting-started.html",
"Categories": [{
"Id": "menuCompilingFromSource",
"Title": "Compiling From Source",
"Resource": "/Documentation/Data/Getting-Started/compiling-from-source.html"
},{
"Id": "menuDownloadReleasePackage",
"Title": "Download Release Package",
"Resource": "/Documentation/Data/Getting-Started/downloading-release-package.html"
},{
"Id": "menuBuildingYourFirstApplication",
"Title": "Building your first application",
"Resource": "/Documentation/Data/Getting-Started/building-your-first-application.html"
}]
}
]
Now, I can retrieve an item out of the menu using jQuery and the result might be this item:
{
"Id": "menuBuildingYourFirstApplication",
"Title": "Building your first application",
"Resource": "/Documentation/Data/Getting-Started/building-your-first-application.html"
}
Now, I want to retrieve all the elements which are at a higher level and all the items which are directly below that item.
Any help is highly appreciated.
JQuery is for querying HTML elements from within the DOM of the current document, not for traversing objects or JSON expression strings.
In any case, given an object, there is no way to "discover" any objects, variables, or arrays that might hold a reference to it.
I'd recommend picking up a decent Javascript book and becoming familiar with the basics. Maybe stay away from things like JQuery at first as they can confuse things for you.
Is it possible to, in 1 request, get the feed of a page but with the full event info?
As it is now, if a shared event is posted, you only get back the link to that event, no picture or title:
{
"id": "xxx",
"from": {
"category": "Community",
"name": "xxx",
"id": "xxx"
},
"story": "xxx shared xxx's event.",
"link": "https://www.facebook.com/events/xxx/",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/xxx/posts/xxx"
},
{
"name": "Like",
"link": "https://www.facebook.com/xxx/posts/xxx"
}
],
"privacy": {
"value": ""
},
"type": "link",
"status_type": "shared_story",
"application": {
"name": "Links",
"id": "xxx"
},
"created_time": "2013-06-19T10:05:50+0000",
"updated_time": "2013-06-19T10:05:50+0000",
"likes": {
"data": [
{
"name": "xxx",
"id": "xxx"
}
],
"count": 1
}
}
If I understand correctly, you need to retrieve the events but you want to do it all at once with the feed because you want to retrieve the information on the feed anyway.
Before doing that, you must know that the feed doesn't contain all the events.... Once created, a link to the event is automatically shared on the page feed. It is only a reference, which can then be hidden. The event won't be displayed on the feed anymore even if it still exists.
Requesting two different objects at the same time
So, the feed doesn't have the events information and the events and posts (feed) are stored on 2 different tables. Therefore, you need to get the events independently from the feed:
The feed /PAGE_ID/feed
The events /PAGE_ID/events
And, as you wanted, Graph API allows you to do this in only one request:
/PAGE_ID?fields=feed,events
Additional fields
Note that either feed or events accept the limit and fields parameters. For example, events can be specified by:
events.limit(100).fields(location,name,owner,description,updated_time,venue)
Possible fields are given in the doc.
There is no way to get the "full info" at once. You will have to specify each field in the request. So, don't get the "full info", but just the information you really need.
There is a post from Facebook addressing this scenario using multi-queries and FQL (Facebook Query Language). This will allow you to make multiple FQL calls in one request.
https://developers.facebook.com/docs/technical-guides/fql/#multi