I have input with the name profile that is basically binded from data as:
data: function() {
return {
profile: {
phone: +123 123 123;
}
}
}
In the input I specify name as profile and v-model as profile.phone. It is sent to backend in the format:
name: profile, value: +123 123 123.
I obviously need to get also the information of the field specified - the phone. It is usually performed by sending name as profile.phone but the backend expects it as:
name: profile
value: {phone: +123 123 123}
The data are sent by sending all data from data. If I want to perform the reformatting that, how do I do that?
I recommend using re-declaring your object with let & this keywords. This will allow you to declare the owner of the function. so you can re-format as:
let profileValue = {
name: 'profile',
value: {
phone: this.profile.phone
}
}
You are sending the data to your back-end server using probably #click event that triggers your POST method? ...
Inside your method you need to construct your object like this...
let profileObj = {
name: 'profile',
value: {
phone : this.profile.phone
}
}
Related
In the screenshot showing list of applications created
function to get list of apps -> ts file
getcmsApps() {
this.getCmsService.getApps().subscribe((res: any) => {
this.data = res;
console.log(res)
})
}
editAppById(appid: string): void {
}
deleteAppId(appid: string){
}
The response you get is an object array. So you can just loop trough the array and access the field by its key name
let AngularResponse = [
{
createdon: "4/1/2022",
division: "test",
email: "aaaa#gmail.com",
fax: "1",
hrbinformation: "1",
id: "d7ab1fc0-0e33-4fb7-ac71-1bf48ddd8bf8"
},
{
createdon: "6/2/2022",
division: "test",
email: "bbbbbb#gmail.com",
fax: "2",
hrbinformation: "2",
id: "a869fdd8-bf99-49d9-bb72-7bb11e6fadbf"
},
]
console.log(AngularResponse[0].id);
//OR to get all of them
AngularResponse.forEach(arrayItem => console.log(arrayItem.id))
Usually the httpService will return an Observable on which you can subscribe in the subscription part you can perform all sorts of operations based on the response you got.
I have to take a look at you code to give you further informations but what I can suggest to do is the following
request = // your http request observable from httpService
request.subscribe((response) => {
// retrieve the id from the response object (as I can see in the
// screenshot your response is an array so you will probably have to loop
// through it)
});
Another option to consider would be to use RxJs operators to make operations on the response object (eventually using the tap operator) before the subscription part.
Hi there I'm trying to make a post request where I want to update one field on sanity.io
this is my query
patch: {
id: "f6c46b53-9313-4354-a4d6-7a40b06ee4c0",
set: {
`rewardItem[_key == \"${key}\"].lastTimeReward`: "TEst",
},
}
but this won't let me even run my project,
its giving me this error on console.log: Unexpected token;
When I do my query like this, it works
patch: {
id: "f6c46b53-9313-4354-a4d6-7a40b06ee4c0",
set: {
"rewardItem[_key == \"e88959e43ce7\"].lastTimeReward": "Test",
},
}
}]
Thanks a lot.
Your set-property is an object, and you can't enter a dynamic key directly into the object. To do what you are trying to do here, you can wrap the dynamic key in square brackets like this. That should give you the output you desire
const variable = "example"
const a = { [`template ${variable}`]: "value" }
console.log(a)
Using Prisma, I have a question about accessing a record that was newly created from within a nested write (update first, then create within).
I'm following along the examples on this page in the prisma docs.
In particular, I am looking at the following two items in the data model:
Note, I have slightly modified the example for the purposes of this question by adding a counter to User.
model User {
id Int #id #default(autoincrement())
email String #unique
posts Post[]
counter Int
}
model Post {
id Int #id #default(autoincrement())
title String
author User? #relation(fields: [authorId], references: [id])
authorId Int?
}
Now, let's say you want to create a new Post and connect it to the User and at the same time, you also want to increment the counter.
My assumption, after reading this section of the doc is that you would need to update the existing User and within that, create a new Post record.
i.e.
const user = await prisma.user.update({
where: { email: 'alice#prisma.io' },
data: {
// increment the counter for this User
counter: {
increment: 1,
},
// create the new Post for this User
posts: {
create: { title: 'Hello World' },
},
},
})
My question is this. In the above scenario, how do you access the newly created Post in the return of the query?
In particular, say you want to get the id of the new Post?
From what I can tell, the returned user object could possibly include the array of all associated Posts, i.e. if you added this to the update query...
include: {
posts: true,
}
But I can't yet see how, using Prisma, you get the individual Post that you just created as part of this update query.
I have found one way of achieving this that works.
It uses the tranaction api.
Basically, instead of trying to use a nested write that begins with an update on User and contains a nested create on Post...
I split the two operations out into separate variables and run them together using a prisma.$transaction() as follows.
const updateUser = prisma.user.update({
where: { email: 'alice#prisma.io' },
data: {
// increment the counter for this User
counter: {
increment: 1,
},
},
});
const createPost = prisma.post.create({
data: {
// create the new Post for this User
title: 'Hello World',
author: {
connect: {
email: 'alice#prisma.io',
},
},
},
});
const [ updateUserResult, createPostResult ] = await prisma.$transaction([updateUser, createPost ]);
// if createPostResult, then can access details of the new post from here...
I have a react and redux application with react final form where I have a field named 'cars' which is a select and on spy fire a submit event if data is dirty. All good with the values and stuff but I need to split that into the types so the form returns something like coupe: ['BMW'], sedan: ['Audi'] not just the field name with values such as cars: ['BMW', 'Audi']
{
type: "Coupe"
value: "BMW"
},
{
type: "Sedan"
value: "Audi"
}
Maybe anyone has a suggestion how to mutate that and when inside react final forms? or should it be done inside a reducer or saga?
Assuming you get your form data as
[
{
type: "Coupe",
value: "BMW"
}, {
type: "Sedan",
value: "Audi"
}
]
and you need to turn type value into the key name, so you get
[{ coupe: 'BMW'}, {sedan: 'Audi'}]
You may use Array.prototype.map() (inside your submit handler, or reducer, or wherever it works better for you):
const formData = [{type:"Coupe",value:"BMW"},{type:"Sedan",value:"Audi"}],
remappedData = formData.map(({type,value}) =>
({[type.toLowerCase()]: value}))
console.log(remappedData)
.as-console-wrapper{min-height:100%;}
I'm trying to collect strings I send from AngularJS to a NodeRED array. The AngularJS code looks like this
this.user =
{
medName1: '',
medTime1: ''
},
{
medName2: '',
medTime2: ''
},
{
medName3: '',
medTime3: ''
};
I'm collecting form data in medName1, medTime1,.. and so on. I'm trying to send this data, over websocket, one by one to NodeRED using the following code
this.register = function() {
$scope.sock.send(this.user.medName1);
$scope.sock.send(this.user.medTime1);
$scope.sock.send(this.user.medName2);
$scope.sock.send(this.user.medTime2);
$scope.sock.send(this.user.medName3);
$scope.sock.send(this.user.medTime3);
}
register() is called when I click on "submit" button.
My question is - How do I store these strings in a nodeRED array?. Because the way I'm sending it, the string always gets stored in array index 0, overwriting the previous string. I also tried
$scope.sock.send(JSON.stringify(this.user));
but it sends the entire thing as a string to nodeRED which then makes it impossible to extract the values assigned to medName1, medTime1, and so on.
Can anyone please suggest a way!.. I'll really appreciate your help.
If you send the json.stingify version, you can then use a JSON node in your Node-RED flow to convert it back to the JavaScript object you want.
First, make your this.user an actual array:
this.user =[
{
medName1: '',
medTime1: ''
},
{
medName2: '',
medTime2: ''
},
{
medName3: '',
medTime3: ''
}];
Then, send the this.user array in a single step just as you mentioned:
this.register = function() {
$scope.sock.send(JSON.stringify(this.user));
}
Then, in NodeRED use this:
var user_array = JSON.parse( the_serialized_array );