i want to bind child nodes to two different kendo ui controls , but my Kendo Data source fetches the data from service in single call ,
var viewModel = kendo.observable {
dataSource : new kendo.data.DataSource({
transport: {
read: {
url: '/data/auras',
dataType: "json",
type: 'GET',
}
},
schema: {
/////////
},
});
}
My JSON response result looks like this
[
{
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters": {
"batter": [
{
"id": "1001",
"type": "Regular"
},
{
"id": "1002",
"type": "Chocolate"
},
{
"id": "1003",
"type": "Blueberry"
},
{
"id": "1004",
"type": "Devil's Food"
}
]
},
"topping": [
{
"id": "5001",
"type": "None"
},
{
"id": "5002",
"type": "Glazed"
},
{
"id": "5005",
"type": "Sugar"
},
{
"id": "5007",
"type": "Powdered Sugar"
},
{
"id": "5006",
"type": "Chocolate with Sprinkles"
},
{
"id": "5003",
"type": "Chocolate"
},
{
"id": "5004",
"type": "Maple"
}
]
}
]
Here I have to bind batter ( is child Element) to One Gridview && topping ( is child Element) to another Gridview ,
You could use schema.parse to split your JSON result into two lists. Something like:
var batters = new kendo.data.DataSource({
data: []
});
var toppings = new kendo.data.DataSource({
data: []
});
var allData = new kendo.data.DataSource({
transport: {
read: {
url: '/data/auras',
dataType: "json",
type: 'GET',
}
},
schema: {
parse: function (data) {
batters.data(data[0].batters.batter);
toppings.data(data[0].toppings);
return data;
}
},
});
allData.fetch();
var viewModel = kendo.observable({
batters: batters,
toppings: toppings
});
Related
I am having issues looping through this data. This data is a the response from a graphql webrequest. I would like to loop through this data and execute another webrequest for each ID. I am not able to get powershell to read the nested objects.
{
"data": {
"Messages": {
"nodes": [
{
"id": "ca96b6e3-b138-46c2-92da-b13d1b2bc03c"
},
{
"id": "05035088-e681-47d1-905d-787c0967897e"
},
{
"id": "8c48af4f-326d-47e5-9714-590521cc3be8"
},
{
"id": "44cf1adc-e451-4140-9fd9-aa3a947f7e2a"
},
{
"id": "d7859528-5385-4e62-b234-a4a7978fe6a3"
},
{
"id": "b62ef4aa-29bf-4f03-9b0b-de8042b68020"
},
{
"id": "ee6e3b25-3f15-4807-9a46-3f9de4867aa5"
},
{
"id": "aed8a312-eac9-4053-abb7-bd93f07dab7a"
},
{
"id": "69421eb8-6c7a-4d80-ba24-c08ca16872c7"
},
{
"id": "9a4ffa1c-0176-420a-9257-5ebfca44b0e4"
},
{
"id": "645777ba-f29d-41c1-b750-939726712f42"
},
{
"id": "702eabb8-50dc-4808-babd-f0317a9cad94"
},
{
"id": "a8b9b755-5fbd-4ab6-8f22-6be1b4c3cc65"
},
{
"id": "e56c473f-4044-4678-9e0c-0e92f04126ad"
},
{
"id": "b3e6c14e-b7fb-451f-afc8-b7f22b1815df"
},
{
"id": "30f4f9be-32cb-4bdd-878f-fa4ff55c89fb"
},
{
"id": "08293318-5e9b-4fa0-919e-6e0611d4f89c"
},
{
"id": "5ea6b3bc-19a5-43d5-ab25-b01770676d49"
},
{
"id": "7f01e29f-6fe6-4b06-a5d5-e3e46f2f74da"
},
{
"id": "59462e10-429e-4878-9cc7-424882e016de"
},
{
"id": "20f3aaa7-a276-4339-bf37-4fe9ff9b2dcf"
},
{
"id": "65a05042-e2de-48b4-80dc-2dfff9ce4c6b"
},
{
"id": "f859f606-e3e6-4d66-8a44-e938b78c08a2"
},
{
"id": "45ce080e-83ca-4a30-84d3-e5e01f3f361a"
},
{
"id": "f8397dc3-027a-4db8-bc6a-e57c219ea836"
},
{
"id": "712cc2e6-270c-4728-a546-6bf43b072a18"
},
{
"id": "551e78cc-db91-491b-8c48-9d9ec2fc8322"
},
{
"id": "eb47d873-bfc7-4d74-ad5a-9f39a2a9cf31"
},
{
"id": "50cc9637-4384-4e47-925d-302b07bb0158"
},
{
"id": "5147ef32-c7e4-443f-97e1-53f3321616c1"
}
]
}
}
}
I tried ConvertFrom-Json but this is all that is see.
data
----
#{Messages=}
I have a model batches which has data as
"id": {
"type": "string",
"id": true,
"defaultFn": "uuidv4"
},
"batchType": {
"type": "string",
"required": true,
"default": "COURSE"
},
"venue": {
"type": "string",
"required": true
},
and another Model say bookedBathes
"batchesId": {
"type": [
"string"
],
"required": true
},
and created a relations from batches model to bookedBatches model as
"relations": {
"bookedBatches": {
"type": "referencesMany",
"model": "bookedBatches",
"foreignKey": "batchesId",
"primaryKey": "id"
}
}
now I want all the batches with booked details that are stored as array's of Id in booked details from batch model
let reqObject = {
"where": {
"and": [{
userId: userId,
isActive: true
}]
},
"order": "createdAt DESC",
include: [
{{
relation:"bookedBatches"}}]
}
Batches.find(reqObject, (resError, resData) => {
if (resError) {
return cb(new HttpErrors.BadRequest(resError, {
expose: false
}))
}
return cb(null, resData);
})
But I am not getting any value can any one help to get the values through relation's
Thank You!
i have improved your code. Please try this
let reqObject = {
"where": {
"and": [{
userId: userId,
isActive: true
}]
},
"order": "createdAt DESC",
include: [
{
relation: "bookedBatches",
scope: { fields: ["id","batchesId"] }
}
]
}
Batches.find(reqObject, (resError, resData) => {
if (resError) {
return cb(new HttpErrors.BadRequest(resError, {
expose: false
}))
}
return cb(null, resData);
})
I'm using loopback 3 to build a backend with mongoDB.
So i have 3 models: Object, Attachment and AwsS3.
Object has a relation Embeds2Many to Attachment.
Attachment has a relation Many2One to AwsS3.
Objects look like that in mongoDB
[
{
"fieldA": "valueA1",
"attachments": [
{
"id": 1,
"awsS3Id": "1234"
},
{
"id": 2,
"awsS3Id": "1235"
}
]
},
{
"fieldA": "valueA2",
"attachments": [
{
"id": 4,
"awsS3Id": "1236"
},
{
"id": 5,
"awsS3Id": "1237"
}
]
}
]
AwsS3 looks like that in mongoDB
[
{
"id": "1",
"url": "abc.com/1"
},
{
"id": "2",
"url": "abc.com/2"
}
]
The question is: how can i get Objects included Attachment and AwsS3.url over the RestAPI?
I have try with the include and scope filter. But it didn't work. It look like, that this function is not implemented in loopback3, right? Here is what i tried over the GET request:
{
"filter": {
"include": {
"relation": "Attachment",
"scope": {
"include": {
"relation": "awsS3",
}
}
}
}
}
With this request i only got the Objects with Attachments without anything from AwsS3.
UPDATE for the relation definitons
The relation from Object to Attachment:
"Attachment": {
"type": "embedsMany",
"model": "Attachment",
"property": "attachments",
"options": {
"validate": true,
"forceId": false
}
},
The relation from Attachment to AwsS3
in attachment.json
"relations": {
"awsS3": {
"type": "belongsTo",
"model": "AwsS3",
"foreignKey": ""
}
}
in AwsS3.json
"relations": {
"attachments": {
"type": "hasMany",
"model": "Attachment",
"foreignKey": ""
}
}
Try this filter:
{ "filter": { "include": ["awsS3", "attachments"]}}}}
i am unable to remove duplicates in Json. In below Json if title field has same values, i need to remove the duplicate node. IN below json title named "car" was repeated 3 times and i need to remove duplicates based on title field. I followed below stackoverflow links but not solved my problem.
Remove duplicate value in dart
Actual Json:
{
"totalSize": 6,
"done": true,
"records": [{
"attributes": {
"type": "ContentVersion",
"url": "https://sampleUrl"
},
"Id": "123456",
"Title": "car",
"Team_Category__c": "Vehicle"
},
{
"attributes": {
"type": "ContentVersion",
"url": "https://sampleUrl"
},
"Id": "123456",
"Title": "car",
"Team_Category__c": "Vehicle"
},
{
"attributes": {
"type": "ContentVersion",
"url": "https://sampleUrl"
},
"Id": "123456",
"Title": "cycle",
"Team_Category__c": "Vehicle"
},
{
"attributes": {
"type": "ContentVersion",
"url": "https://sampleUrl"
},
"Id": "123456",
"Title": "aeroplane",
"Team_Category__c": "Vehicle"
},
{
"attributes": {
"type": "ContentVersion",
"url": "https://sampleUrl"
},
"Id": "123456",
"Title": "car",
"Team_Category__c": "Vehicle"
}
]
}
Add kt_dart: to your pubspec.
Then import it in your dart file import 'package:kt_dart/kt.dart';
Then:
var json = jsonDecode(yourJsonAsString);
var records = mutableListFrom(json["records"]);
var distinct = records.distinctBy((it) => it["Title"]);
if nothing works out, you can create new similar structure and add only distinct items into it as below. I am not a dart programmer but it is a naive solution.
import 'dart:convert';
void main() {
var jsonData = '[{ "name" : "Dane", "alias" : "FilledStacks" },{ "name" : "Dane", "alias" : "FilledStacks" }]';
List uniqueList = new List();
List parsedJson = json.decode(jsonData);
for (var jsonElement in parsedJson) {
bool isPresent = false;
for (var uniqueEle in uniqueList) {
if (uniqueEle['name'] == jsonElement['name']) isPresent = true;
}
if (!isPresent) uniqueList.add(jsonElement);
}
print('$uniqueList');
print('');
print('${parsedJson.runtimeType} : $parsedJson');
}
I want to enable account linking on an Google Assistant application using Actions Sdk.
I have already provided the information in the Account Linking section of the AoG Console :
The grant Type is Authorization code.
I use Auth0 as Oauth Server and i checked that the endpoints are functional.
When the application is invoked using the simulator, the server application send the following json response :
{
"expectUserResponse": true,
"finalResponse": null,
"expectedInputs": [{
"possibleIntents": [{
"intent": "actions.intent.SIGN_IN",
"inputValueData": null
}],
"inputPrompt": {
"richInitialPrompt": {
"items": [{
"simpleResponse": {
"textToSpeech": "Merci de vous authentifier",
"ssml": null,
"displayText": "Merci de vous authentifier"
}
}]
}
}
}],
"conversationToken": null,
"isInSandbox": false
}
I expected then to see the message like : it looks like your account … is not linked
Instead of that, the assistant immediately sends the following request to the server :
{
"user": {
"userId": "ABwppHGK6fClByrbLlS8WDM4xfY0qEck5i_kOGMhlJtuj64SjC-8qDqlH3xZ3BN7f9Yz1JDza-sc",
"locale": "fr-CA",
"lastSeen": "2018-04-23T14:12:02Z"
},
"conversation": {"conversationId": "1524493058716", "type": "NEW"},
"inputs": [{
"intent": "actions.intent.SIGN_IN",
"rawInputs": [{"inputType": "KEYBOARD"}],
"arguments": [{
"name": "SIGN_IN",
"extension": {
"#type": "type.googleapis.com/google.actions.v2.SignInValue",
"status": "ERROR"
}
}]
}],
"surface": {
"capabilities": [
{"name": "actions.capability.WEB_BROWSER"},
{"name": "actions.capability.MEDIA_RESPONSE_AUDIO"},
{"name": "actions.capability.SCREEN_OUTPUT"},
{"name": "actions.capability.AUDIO_OUTPUT"}
]
},
"isInSandbox": true,
"availableSurfaces": [
{
"capabilities": [
{"name": "actions.capability.SCREEN_OUTPUT"},
{"name": "actions.capability.AUDIO_OUTPUT"}
]
}
]
}
Did someone have the same problem ? Thanks
I have a working example, but it might be different of what you are doing because I ask the sign-in with dialogflow Integrations' tab for Google Assistant, and not explicitely with the SDK. The code is for the V2 of Dialogflow, I also have one for the V1 but it is now legacy.
This is my BONJOUR intent that is triggered when my app is launched:
const rp = require('request-promise');
app.intent('BONJOUR', (conv) => {
console.log("Debug: SAY_HELLO");
const accessToken = conv.user.access.token;
console.log("Access Token = "+accessToken);
//========Auth with OAuth website========
if (!accessToken) {
conv.ask(new SignIn());
} else {
let options = {
method: 'GET',
url: '[...]',//Oauth URL
headers:{
authorization: 'Bearer ' + accessToken,
}
};
// I use the RP lib as we need Promises for the V2 of Dialogflow.
return rp(options).then((body) => {
let data = JSON.parse(body);
console.log("auth data ="+JSON.stringify(data));
//You can access the auth data easily here
// For example if you want the name, it's in data.given_name, etc...
//Use conv.ask() to say something here
}).catch((error) => {
console.log("Error in auth request"+error);
})
}
});
Update:
This is my JSON mais the SignIn() is called, as I just tested it, it doesn't work (I created an intent that receives the actions_intent_SIGN_IN event from an example. And it never asks for sign In , I'm always in the else.)
Response {
"payload": {
"google": {
"expectUserResponse": true,
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "PLACEHOLDER"
}
}
]
},
"userStorage": "{\"data\":{}}",
"systemIntent": {
"intent": "actions.intent.SIGN_IN",
"data": {
"#type": "type.googleapis.com/google.actions.v2.SignInValueSpec"
}
}
}
},
"outputContexts": [
{
"name": [...],
"lifespanCount": 99,
"parameters": {
"data": "{}"
}
}
]
}
Then the request after that is:
Request {
"responseId": "5a711f0e-be66-4311-b776-2085e81e9bde",
"queryResult": {
"queryText": "actions_intent_SIGN_IN",
"parameters": {},
"allRequiredParamsPresent": true,
"fulfillmentMessages": [
{
"text": {
"text": [
""
]
}
}
],
"outputContexts": [
{
"name": "..."
},
{
"name": ".../actions_intent_sign_in",
"parameters": {
"SIGN_IN": {
"#type": "type.googleapis.com/google.actions.v2.SignInValue",
"status": "ERROR"
}
}
},
{
"name": "...",
"lifespanCount": 98,
"parameters": {
"data": "{}"
}
},
{
"name": "..."
},
{
"name": "..."
},
{
"name": "..."
},
{
"name": "..."
}
],
"intent": {
"name": "...",
"displayName": "Get Signin"
},
"intentDetectionConfidence": 1,
"diagnosticInfo": {},
"languageCode": "fr-fr"
},
"originalDetectIntentRequest": {
"source": "google",
"version": "2",
"payload": {
"isInSandbox": true,
"surface": {
"capabilities": [
{
"name": "actions.capability.WEB_BROWSER"
},
{
"name": "actions.capability.MEDIA_RESPONSE_AUDIO"
},
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.AUDIO_OUTPUT"
}
]
},
"inputs": [
{
"rawInputs": [
{
"inputType": "KEYBOARD"
}
],
"arguments": [
{
"extension": {
"#type": "type.googleapis.com/google.actions.v2.SignInValue",
"status": "ERROR"
},
"name": "SIGN_IN"
}
],
"intent": "actions.intent.SIGN_IN"
}
],
"user": {
"userStorage": "{\"data\":{}}",
"lastSeen": "2018-04-24T12:21:19Z",
"locale": "fr-FR",
"userId": "ABwppHHXrOc7N24RC5YS1dMvt7C-MbpzTb5TtzmufeIpGTCINVlReIMb8RKo4SGQMgBY7BUvO1qhn0B-"
},
"conversation": {
"conversationId": "1524572717282",
"type": "ACTIVE",
"conversationToken": "[\"_actions_on_google\"]"
},
"availableSurfaces": [
{
"capabilities": [
{
"name": "actions.capability.SCREEN_OUTPUT"
},
{
"name": "actions.capability.AUDIO_OUTPUT"
}
]
}
]
}
},
"session": "..."
}
I hope it can help you somehow.