How to insert a list into a map? - dart

I have 2 data one in an array and the other in a list. I need to send these data in API but combine them.
My first data look like this:
data1 = {vendorId: 17, vendorName: Dolphin Bakers};
and second is like this
data2 = [
{id: 3, province: and, code: 56201},
{id: 3, province: and, code: 56201},
];
I need to send it like this
{
vendorId: 17,
vendorName: Dolphin Bakers,
data: [
{id: 3, province: and, code: 56201},
{id: 3, province: and, code: 56201},
],
}
I am trying to add second data in the first data
data1.add(data: data2);
Its showing error Class '_InternalLinkedHashMap<String, dynamic>' has no instance method 'add'.

You must put a "data" key in the map:
data1["data"] = data2;

Related

Generate data for secionlists in react native

The SectionList in react native requires the data feed like the following:
sections={[
{title: 'D', data: ['Devin']},
{title: 'J', data: ['Jackson', 'James', 'Jillian', 'Jimmy', 'Joel', 'John', 'Julie']},
]}
My understanding of data above is a object of object array. I can generate an object array like this:
let obj_arr = [];
obj1 = {
a: 1,
b: 2
};
obj_arr.push(obj1);
obj2 = {
c: 3,
b: 4
};
obj_arr.push(obj2);
How to generate object for object array of obj_arr?

Flutter - Search elements in array with firstwhere

The problem is simple: What is the correct way to search element in array ?
My code is
data = [{id: 1, descripcion: Asier}, {id: 2, descripcion: Pepe}]
estateSelected= data.firstWhere((dropdown)=>dropdown.id==1);
The error that return is
Bad state: no element
You have some errors, this should work:
var data = [{'id': 1, 'descripcion': 'Asier'}, {'id': 2, 'descripcion': 'Pepe'}];
var estateSelected = data.firstWhere((dropdown) => dropdown['id'] == 1);
print(estateSelected);
Fastest way to try is on dartpad

Exporting Multiple HTML tables to excel such that each HTML table is in a new column

I'm trying to use alasql to export a set of HTML tables into an excel document.
The documentation has code that looks similar to this:
var data1 = alasql('SELECT * FROM HTML("#dev-table",{headers:false})');
var data2 = alasql('SELECT * FROM HTML("#dev2-table",{headers:false})');
var data3 = alasql('SELECT * FROM HTML("#dev3-table",{headers:false})');
//var data4 = alasql('SELECT * FROM HTML("#dev2-table",{headers:true})');
var data = data1.concat(data2, data3);
alasql('SELECT * INTO XLS("data.xls",{headers:false}) FROM ?', [data]);
The problem is that this code concatenates the data1 and data2 field so that all of the data is printed in the same column. This is not the result I desire. I want "data1" to go into column "A" and data2 to go into column "B".
I've looked through the documentation and am unsure how to get the desired result. I'm aware of the existence of "options" that include fields for specifying columns based on the data itself, but none of those examples are what I want. If this is not possible using alasql, I'm willing to use a different library or framework for this.
Based on this JSFiddle, http://jsfiddle.net/95j0txwx/7/
$scope.items = [{
name: "John Smith",
email: "j.smith#example.com",
dob: "1985-10-10"
}, {
name: "Jane Smith",
email: "jane.smith#example.com",
dob: "1988-12-22"
},
...
I would guess that your data is not formatted correctly to be inserted.
EDIT: JSFiddle is from documentation. https://github.com/agershun/alasql/wiki/XLSX

Neo4j Batch update of data

How can I do multiple Nodes update in neo4j cypher?
Now I'm trying to do like this:
MATCH (user151325288158:User{userId:151325288158}),
(user88245:User{userId:88245})
SET user151325288158.balance=2902833.4219789803
SET user88245.balance=146701.0299999991
RETURN user151325288158.balance,user88245.balance;
But here I have problem that if such user is absent in DB, nobody will be updated.
Other problem is performance, such queries are slow.
Is there some method to do such bulk updates?
Assuming you have pairs of userIds and new balance values in an array of maps/dicts, like this:
[
{
"userId": 151325288158,
"balance": 146701.09
},
{
"userId": 887436512344,
"balance": 22453.34
},
{
"userId": 873927654232,
"balance": 300002.22
}
]
You can pass this array as a parameter to a Cypher query to MATCH on the userId and update the balance property like this:
WITH {data} AS pairs
UNWIND pairs AS p
MATCH (u:User) WHERE u.userId = p.userId
SET u.balance = p.balance
By following William Lyon's answer, I was able to implement a batch update of multiple properties as follows:
UNWIND [{id: 123456, name: "John", age: 27}, {id: 789012, name: "Jane", age: 24}] AS updateUser
MATCH (user: User)
WHERE user.id = updateUser.id
SET user += updateUser
RETURN user

How to structure falcor router to get all available IDs?

I'm experimenting with using Falcor to front the Guild Wars 2 API and want to use it to show game item details. I'm especially interested in building a router that can use multiple datasources to combine the results of different APIs.
The catch is, Item IDs in Guild Wars 2 aren't contiguous. Here's an example:
[
1,
2,
6,
11,
24,
56,
...
]
So I can't just write paths on the client like items[100..120].name because there's almost certainly going to be a bunch of holes in that list.
I've tried adding a route to my router so I can just request items, but that sends it into an infinite loop on the client. You can see that attempt on GitHub.
Any pointers on the correct way to structure this? As I think about it more maybe I want item.id instead?
You shouldn't find your self asking for ids from a Falcor JSON Graph object.
It seems like you want to build an array of game ids:
{
games: [
{ $type: "ref", value: ["gamesById", 352] },
{ $type: "ref", value: ["gamesById", 428] }
// ...
],
gamesById: {
352: {
gameProp1: ...,
},
428: {
gameProp2: ...
}
}
}
[games, {from: 5, to: 17 }, "gameProp1"]
Does that work?
You can use 'get' API of Falcor, It retrieves multiple values.. You can pass any number of required properties as shown below
var model=new falcor.Model({
cache:{
genereList:[
{name:"Recently Watched",
titles:[
{id:123,
name: "Ignatius",
rating: 4}
]
},
{name:"New Release",
titles:[
{id:124,
name: "Jessy",
rating: 3}
]
}
]
}
});
Getting single value
model.getValue('genereList[0].titles[0].name').
then(function(value){
console.log(value);
});
Getting multiple values
model.get('genereList[0..1].titles[0].name', 'genereList[0..1].titles[0].rating').
then(function(json){
console.log(JSON.stringify(json, null, 4));
})

Resources