Hello im trying to append the media size for my image set so the first image should have the mediaSize 768px the second 1024 and so on, how can i wrap it up. i would like to use the values for my srcset : to set the min width for media.
here is my Object
data = {[
{
thumbnail: 'http://via.placeholder.com/90x90',
images:
[
'http://via.placeholder.com/768x400',
'http://via.placeholder.com/1024x400',
'http://via.placeholder.com/1999x400',
{mediaSize : [ "768px", "1024px","1999px "]}
]
}
]}
var data = [
{
'thumbnail': 'http://via.placeholder.com/90x90',
'images':
[
{ 'link': 'http://via.placeholder.com/768x400' },
{ 'link1': 'http://via.placeholder.com/1024x400' },
{ 'link2': 'http://via.placeholder.com/1999x400' },
{
'mediaSize': [
{ 'id': "768px" },
{ 'id1': "1024px" },
{ 'id2': "1999px" },
]
},
]
}
]
check this....
var data = [
{
"CategoryID": 1,
"CategoryName": "Soler Power Plant",
"CategoryProducts": [
{
"ID": 1,
"Name": 'Commercial Solar Power Plant',
"SubTitle": 'Eco, Eco Friendly, Energy, Green, Solar',
"Brand": 'ACS',
"Usage": '',
"Type": '',
"Price": 'Rs 5 Lakh / Unit',
"Body_Material": '',
"Description": 'Having a pre-determined quality administration system, we are thoroughly involved in delivering Commercial Solar Power Plant.',
"ImageUrl": 'assets/images/Products/Sola-power-plant.jpg',
}]
}]
Related
I'm getting this data from backend and need paste it in my Apex Charts chart - https://apexcharts.com/javascript-chart-demos/area-charts/spline/
{
"ADA": {
"name": "ADA",
"data": [
0,
0,
"98"
]
},
"MATIC": {
"name": "MATIC",
"data": [
"127",
"128",
"65"
]
},
"DOT": {
"name": "DOT",
"data": [
0,
"6",
"6"
]
}
}
Config looks like this with my stupid non iterate solution that works (series it's common array, inside objects with name/data)
series: [
{
name: props.portfolioGrowthData.data.chart_tokens_data.MATIC.name,
data: props.portfolioGrowthData.data.chart_tokens_data.MATIC.data.map(
(x, index) => x
),
},
{
name: props.portfolioGrowthData.data.chart_tokens_data.ADA.name,
data: props.portfolioGrowthData.data.chart_tokens_data.ADA.data.map(
(x, index) => x
),
},
{
name: props.portfolioGrowthData.data.chart_tokens_data.DOT.name,
data: props.portfolioGrowthData.data.chart_tokens_data.DOT.data.map(
(x, index) => x
),
},
],
But this solution it's not what i need because empty tokens displays in chart too and after scale of our app there gonna be a mess of tokens. Looks like i need somehow handle data from backend and iterate objects without static name and data but all my tries are failed... How can i handle it?
I have JSON format like this I not sure how do I create new array of objects from an different array of object
[
{
"description":"microsoftLocation",
"icon":"Marker",
"data_id":"123",
"reference":"_1_microsoftOffice",
"id":1,
"text":"microsoftOffice"
},
{
"description":"facebookOffice",
"icon":"Marker",
"data_id":"456",
"reference":"_2_facebookOffice",
"id":2,
"text":"_2_microsoftOffice"
},
]
I want the output to look something like this and not sure how to get the dynamic url as well
[
{
"url":"http://localhost:3000/layer?text=microsoftLocation&data_id=123",
"text":"microsoftLocation",
"active":true,
"icon":Marker
},
{
"url":"http://localhost:3000/layer?text=facebookOffice&data_id=123",
"text":"facebookOffice",
"active":true,
"icon":Marker
},
]
You can do it using a map like this:
const data = [{
"description": "microsoftLocation",
"icon": "Marker",
"data_id": "123",
"reference": "_1_microsoftOffice",
"id": 1,
"text": "microsoftOffice"
},
{
"description": "facebookOffice",
"icon": "Marker",
"data_id": "456",
"reference": "_2_facebookOffice",
"id": 2,
"text": "_2_microsoftOffice"
},
];
const newData = data.map(el => ({
url: `http://localhost:3000/layer?text=${el.description}&data_id=${el.data_id}`,
text: el.description,
active: true,
icon: el.icon
}));
console.log(newData);
Just use map method in order to map from the original object properties to the new ones.
const array = [
{
"description":"microsoftLocation",
"icon":"Marker",
"data_id":"123",
"reference":"_1_microsoftOffice",
"id":1,
"text":"microsoftOffice"
},
{
"description":"facebookOffice",
"icon":"Marker",
"data_id":"456",
"reference":"_2_facebookOffice",
"id":2,
"text":"_2_microsoftOffice"
},
];
console.log(array.map(obj => ({ icon: obj.icon, active: true, text: obj.description, url: `http://localhost:3000/layer?text=${obj.description}&data_id=${obj.data_id}`})))
For Example
Suppose that using the models below, there is one task, t.
I would like to create a sequence for doing task t twice. In the database, this is represented by two rows in the taskSequences with unique ids and different sequence numbers.
However, when I try to use sequelize to retrieve the sequence and its tasks using this query:
models.sequence.findByPk(1, {include: [{model: models.task}]})
, the result only contains one of the tasks.
Is this a limitation of sequelize, or am I missing something?
Models
Sequence Model
const sequence = sequelize.define('sequence', {
name: DataTypes.STRING
}, {});
sequence.associate = function(models) {
sequence.belongsToMany(models.task, {
through: models.taskSequence,
foreignKey: "sequence_id",
otherKey: "task_id"
}
}
Task Model
const task = sequelize.define('task', {
name: DataTypes.STRING
}, {});
sequence.associate = function(models) {}
TaskSequence Model
const taskSequence= sequelize.define('taskSequence', {
sequenceNumber: DataTypes.INTEGER,
task_id: DataTypes.INTEGER,
sequence_id: DataTypes.INTEGER
}, {});
sequence.associate = function(models) {
taskSequence.belongsTo(models.task, {foreignKey: "task_id"});
taskSequence.belongsTo(models.sequence, {foreignKey: "sequence_id"});
}
Output
Expected
{
"id": 1,
"name": "Example Sequence",
"tasks": [
{
"id": 1,
"name": "Example Task",
"taskSequence": {
"sequenceNumber": 1,
"task_id": 1,
"sequence_id": 1,
}
},
{
"id": 1,
"name": "Example Task",
"taskSequence": {
"sequenceNumber": 2,
"task_id": 1,
"sequence_id": 1,
}
}
]
}
What I'm getting
{
"id": 1,
"name": "Example Sequence",
"tasks": [
{
"id": 1,
"name": "Example Task",
"taskSequence": {
"sequenceNumber": 2,
"task_id": 1,
"sequence_id": 1,
}
}
]
}
Yes, it is a limitation of Sequelize. It filters out duplicates by default. You should be able to workaround it like this:
models.sequence.findByPk(1, {
include: [{
model: models.taskSequence,
include: [{
model: models.task,
}]
}]
})
The downside is that the returned data structure will be different from what you want initially
i'm trying to assign/merge (really don't know which lodash function) to nested json objects.
I have the following json structure:
{
"sports": [{
"id": "c60d0c48-151e-4fa2-bdf8-48cdfa77ad1d",
"name": "Soccer",
"slug": "soccer"
}],
"competitions": [{
"id": "4c19ca7c-4d17-46ce-bb4e-e25a4ebe5dbe",
"name": "English Premier League",
"sportId": "c60d0c48-151e-4fa2-bdf8-48cdfa77ad1d"
}],
"contests": [{
"id": "09cee598-7736-4941-b5f5-b26c9da113fc",
"name": "Super Domingo Ingles",
"status": "live",
"competitionId": "4c19ca7c-4d17-46ce-bb4e-e25a4ebe5dbe"
}]
}
I want to get one contest object with their relationship linked nested. The expected object is something like this:
{
"id": "09cee598-7736-4941-b5f5-b26c9da113fc",
"name": "Super Domingo Ingles",
"status": "live",
"competition": {
"id": "4c19ca7c-4d17-46ce-bb4e-e25a4ebe5dbe",
"name": "English Premier League",
"sport": {
"id": "c60d0c48-151e-4fa2-bdf8-48cdfa77ad1d",
"name": "Soccer",
"slug": "soccer"
}
}
}]
}
How can I get this kinda of relationship done using lodash ? It can be using pure javascript as well.
You don't need any special assignment operator, or lodash. You just use the =.
ogObject = {
"sports": [{
"id": "c60d0c48-151e-4fa2-bdf8-48cdfa77ad1d",
"name": "Soccer",
"slug": "soccer"
}],
"competitions": [{
"id": "4c19ca7c-4d17-46ce-bb4e-e25a4ebe5dbe",
"name": "English Premier League",
"sportId": "c60d0c48-151e-4fa2-bdf8-48cdfa77ad1d"
}],
"contests": [{
"id": "09cee598-7736-4941-b5f5-b26c9da113fc",
"name": "Super Domingo Ingles",
"status": "live",
"competitionId": "4c19ca7c-4d17-46ce-bb4e-e25a4ebe5dbe"
}]
};
newObject = ogObject.contests[0];
for(var i = 0; i<ogObject.competitions.length;i++){
if(ogObject.competitions[i].id == newObject.competitionId){
newObject.competition = ogObject.competitions[i];
for(var j = 0; j<ogObject.sports.length;j++){
if(ogObject.sports[j].id == newObject.competition.sportId){
newObject.competition.sport = ogObject.sports[j];
break;
}
}
break;
}
}
console.log(newObject)
This might be a builtin from lodash but I doubt it. It would require predefined knowledge of your schema vis-a-vis the relationship between sportId and sports, competitionId and competitions etc...
You really need to show us what you have tried so that we can advise you about the problems that you are facing, otherwise you are just asking for a code writing service ($).
However, in ES2016 you could do this.
'use strict';
const obj = {
sports: [{
id: 'c60d0c48-151e-4fa2-bdf8-48cdfa77ad1d',
name: 'Soccer',
slug: 'soccer',
}],
competitions: [{
id: '4c19ca7c-4d17-46ce-bb4e-e25a4ebe5dbe',
name: 'English Premier League',
sportId: 'c60d0c48-151e-4fa2-bdf8-48cdfa77ad1d',
}],
contests: [{
id: '09cee598-7736-4941-b5f5-b26c9da113fc',
name: 'Super Domingo Ingles',
status: 'live',
competitionId: '4c19ca7c-4d17-46ce-bb4e-e25a4ebe5dbe',
}],
};
const transformed = obj.contests.map((contest) => {
const competition = obj.competitions.find(item => item.id === contest.competitionId);
const sport = obj.sports.find(item => item.id === competition.sportId);
const sportLevel = { ...sport };
const competitionLevel = { ...competition, sport: sportLevel };
delete competitionLevel.sportId;
const contestLevel = { ...contest, competition: competitionLevel };
delete contestLevel.competitionId;
return contestLevel;
});
console.log(JSON.stringify(transformed, null, 2));
There's no built-in lodash function that can be used to flatten relational JSON structures. But something like this should work for you:
const sourceJSON = {
"sports": [{
"id": "c60d0c48-151e-4fa2-bdf8-48cdfa77ad1d",
"name": "Soccer",
"slug": "soccer"
}],
"competitions": [{
"id": "4c19ca7c-4d17-46ce-bb4e-e25a4ebe5dbe",
"name": "English Premier League",
"sportId": "c60d0c48-151e-4fa2-bdf8-48cdfa77ad1d"
}],
"contests": [{
"id": "09cee598-7736-4941-b5f5-b26c9da113fc",
"name": "Super Domingo Ingles",
"status": "live",
"competitionId": "4c19ca7c-4d17-46ce-bb4e-e25a4ebe5dbe"
}]
}
function findSport(source, sportId) {
let sport = _.find(source['sports'], {id: sportId});
if(!sport) {
return {};
}
return {
id: sport.id,
name: sport.name,
slug: sport.slug,
}
}
function findCompetition(source, competitionId) {
let competition = _.find(source['competitions'], {id: competitionId});
if(!competition) {
return {};
}
return {
id: competition.id,
name: competition.name,
sport: findSport(source, competition.sportId),
}
}
function flattenContests(source) {
return _.map(source['contests'], (contest) => {
return {
id: contest.id,
name: contest.name,
status: contest.status,
competition: findCompetition(source, contest.competitionId),
}
});
}
console.log(flattenContests(sourceJSON));
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js"></script>
Note that considering your original JSON, the flattened object should likely be an array of contests (since contests itself is an array) instead of a single contest object that you're expecting.
Below i mentioned the design document.
{
"_id": "_design/link",
"_rev": "62-0c0f00dd9dbedab5c2cca61c356bbff4",
"views": {
"link": {
"map": "function(doc) {\n if (doc.projects) { for (var i in doc.projects) { emit(doc._id, {_id: doc.projects[i].proj_id}); }} \n}"
},
"lists": {
"sample": "function(head, req) {while(row = getRow()){ send(row.doc.proj_name);} }"
}
}
}
The view result:
{
total_rows: 1,
offset: 0,
rows: [
{
id: "SCI130202",
key: "SCI130202",
value: {
_id: "PID00034"
},
doc: {
_id: "PID00034",
_rev: "1-0a363e98a605a72fd71bb4ac62e0b138",
client_id: "E000022",
client_name: "Edinburgh Steel",
type: "manage projects",
proj_id: "PID00034",
proj_name: "Global_upgrade_Oracle",
proj_domain: "Information Technology",
proj_start_date: "2014-10-08",
proj_end_date: "2015-07-07",
delivery_manager: null,
proj_standards: null,
proj_currency_type: "INR",
onsite: "No",
location: "Edinburgh",
proj_status: "Noy yet Start",
budgeted_margin: 45,
budgeted_hrs: 300,
projected_revenue: 200000,
billing_rate: 30,
unit_measure: "per month",
billing_cycle: "Milestone",
proj_core_tech_skills: [ ],
proj_secon_skills: [ ],
proj_sdlc_skills: [ ],
tag: "",
margin: [
{
desired_onsite: null,
desired_offshore: null,
lower_limit: null
}
]
}
}
]
}
I tried but the error comes like
function raised error: (new TypeError("row.doc is undefined", ""))
How to get the proj_name,proj_start_date and proj_end_date using couchdb list function?
You need to add the include_docs=true option to the URL you are using to query the view/list. Views do not automatically include the document.
And maybe you shouldn't use a list to filter your view result - just let the view emit what you need:
emit(doc._id, {
_id: doc.projects[i].proj_id
});
Turns into:
emit(doc.proj_id, {
proj_name: doc.proj_name,
proj_id: doc.proj_id,
proj_start_date: doc.proj_start_date,
proj_end_date: doc.proj_end_date
});
You don't need to emit the doc._id - it is automatically emitted for every row.