The problem is that if the children are larger than 30 pieces then the latest box rises to the top and spoils the entire structure.
I took here some code examples for you.
Please help me, I can't explain problem in details because my English is very bad.
dataSource: [
{ id: 1, parentId: null, name: "Amber McKenzie"},
{ id: 2, parentId: 1, name: "Ava Field"},
{ id: 37, parentId: 2, name: "Evie Johnson"},
{ id: 3, parentId: 1, name: "Evie Johnson"},
{ id: 4, parentId: 1, name: "Evie Johnson"},
{ id: 5, parentId: 1, name: "Evie Johnson"},
{ id: 6, parentId: 1, name: "Evie Johnson"},
{ id: 7, parentId: 1, name: "Evie Johnson"},
{ id: 8, parentId: 1, name: "Evie Johnson"},
{ id: 9, parentId: 1, name: "Evie Johnson"},
{ id: 10, parentId: 1, name: "Evie Johnson"},
{ id: 11, parentId: 1, name: "Evie Johnson"},
{ id: 12, parentId: 1, name: "Evie Johnson"},
{ id: 13, parentId: 1, name: "Evie Johnson"},
{ id: 14, parentId: 1, name: "Evie Johnson"},
{ id: 15, parentId: 1, name: "Evie Johnson"},
{ id: 16, parentId: 1, name: "Evie Johnson"},
{ id: 17, parentId: 1, name: "Evie Johnson"},
{ id: 18, parentId: 1, name: "Evie Johnson"},
{ id: 19, parentId: 1, name: "Evie Johnson"},
{ id: 20, parentId: 1, name: "Evie Johnson"},
{ id: 21, parentId: 1, name: "Evie Johnson"},
{ id: 22, parentId: 1, name: "Evie Johnson"},
{ id: 23, parentId: 1, name: "Evie Johnson"},
{ id: 24, parentId: 1, name: "Evie Johnson"},
{ id: 25, parentId: 1, name: "Evie Johnson"},
{ id: 26, parentId: 1, name: "Evie Johnson"},
{ id: 27, parentId: 1, name: "Evie Johnson"},
{ id: 28, parentId: 1, name: "Evie Johnson"},
{ id: 29, parentId: 1, name: "Evie Johnson"},
{ id: 30, parentId: 1, name: "Evie Johnson"},
{ id: 31, parentId: 1, name: "Evie Johnson"},
{ id: 32, parentId: 1, name: "Evie Johnson"}
]
The default value of maxDepth option is 30. In you case you have to increase it. Here is an example:
var orgchart = new getOrgChart(document.getElementById("people"), {
primaryFields: ["name"],
layout: getOrgChart.MIXED_HIERARCHY_RIGHT_LINKS,
maxDepth: 50,
Related
I have an array of grades in mongoose, with students inside each grade nested in that array. I've been trying to sort the number of laps each student has inside of one array, but the sort function isn't sorting them; it leaves them in the formation they were in.
[
name: 'Grade A',
user: 625b2ea7a921450275bd9500,
students: [
{
_id: 625d8f55a856e935cebe070a,
name: 'OB',
laps: 18,
time: 2022-05-15T15:28:39.734Z,
avgSpeed: 307.32371093750004,
topSpeed: 663.36
},
{
_id: 625d8f5ca856e935cebe070b,
name: 'CB',
laps: 7,
time: 2022-05-15T15:20:33.618Z,
topSpeed: 9562.13,
avgSpeed: 944.2103125
},
{
_id: 625d8f62a856e935cebe070c,
name: 'CC',
laps: 5,
time: 2022-05-14T19:59:31.637Z,
avgSpeed: 3.245,
topSpeed: 6.49
},
{
_id: 625d8f67a856e935cebe070d,
name: 'JC',
laps: 6,
time: 2022-05-14T19:57:05.646Z,
avgSpeed: 516.751875,
topSpeed: 7128.13
},
{
_id: 625d8f6aa856e935cebe070e,
name: 'EE',
laps: 5,
time: 2022-05-15T15:18:13.486Z,
avgSpeed: 2904.3375,
topSpeed: 10317.03
},
{
_id: 625d8f70a856e935cebe070f,
name: 'LF',
laps: 3,
time: 2022-05-14T19:09:00.683Z
},
{ _id: 625d8f78a856e935cebe0710, name: 'RH', laps: 2 },
{
_id: 625d8f7ea856e935cebe0711,
name: 'AH',
laps: 22,
time: 2022-05-14T19:06:35.126Z
},
{ _id: 625d901b6922d33754e48622, name: 'SM' },
{ _id: 625d90206922d33754e48623, name: 'CP' },
{ _id: 625d90256922d33754e48624, name: 'SS' },
{
_id: 625d902b6922d33754e48625,
name: 'NT',
laps: 3,
time: 2022-05-15T15:26:21.236Z,
avgSpeed: 582.14,
topSpeed: 605.01
},
{
_id: 625d902f6922d33754e48626,
name: 'IZ',
laps: 3,
time: 2022-05-15T15:22:45.552Z,
topSpeed: 9117.38,
avgSpeed: 2569.3199999999997
},
{
_id: 6261d505122d0a073be3fc73,
name: 'Mr. T',
laps: 59,
time: 2022-05-15T15:14:43.743Z,
topSpeed: 997.58,
avgSpeed: 102.66416015625
}
],
topSpeed: [],
topLaps: [],
createdAt: 2022-04-18T16:18:10.578Z,
__v: 0
},
{
_id: 625d88094d09ed2e5090f91b,
name: 'Grade B',
user: 625b2ea7a921450275bd9500,
students: [
{
_id: 625d8f55a856e935cebe070a,
name: 'j',
laps: 18,
time: 2022-05-15T15:28:39.734Z,
avgSpeed: 307.32371093750004,
topSpeed: 663.36
},
{
_id: 625d8f5ca856e935cebe070b,
name: 'i',
laps: 7,
time: 2022-05-15T15:20:33.618Z,
topSpeed: 9562.13,
avgSpeed: 944.2103125
},
{
_id: 625d8f62a856e935cebe070c,
name: 'h',
laps: 5,
time: 2022-05-14T19:59:31.637Z,
avgSpeed: 3.245,
topSpeed: 6.49
},
{
_id: 625d8f67a856e935cebe070d,
name: 'h',
laps: 6,
time: 2022-05-14T19:57:05.646Z,
avgSpeed: 516.751875,
topSpeed: 7128.13
},
{
_id: 625d8f6aa856e935cebe070e,
name: 'j',
laps: 5,
time: 2022-05-15T15:18:13.486Z,
avgSpeed: 2904.3375,
topSpeed: 10317.03
},
{
_id: 625d8f70a856e935cebe070f,
name: 'iF',
laps: 3,
time: 2022-05-14T19:09:00.683Z
},
{ _id: 625d8f78a856e935cebe0710, name: 'H', laps: 2 },
{
_id: 625d8f7ea856e935cebe0711,
name: 'g',
laps: 22,
time: 2022-05-14T19:06:35.126Z
},
{ _id: 625d901b6922d33754e48622, name: 'd' },
{ _id: 625d90206922d33754e48623, name: 'f' },
{ _id: 625d90256922d33754e48624, name: 'e' },
{
_id: 625d902b6922d33754e48625,
name: 'c',
laps: 3,
time: 2022-05-15T15:26:21.236Z,
avgSpeed: 582.14,
topSpeed: 605.01
},
{
_id: 625d902f6922d33754e48626,
name: 'b',
laps: 3,
time: 2022-05-15T15:22:45.552Z,
topSpeed: 9117.38,
avgSpeed: 2569.3199999999997
},
{
_id: 6261d505122d0a073be3fc73,
name: 'a',
laps: 59,
time: 2022-05-15T15:14:43.743Z,
topSpeed: 997.58,
avgSpeed: 102.66416015625
}
],
topSpeed: [],
topLaps: [],
createdAt: 2022-04-18T15:47:21.875Z,
__v: 0
}
]
I've tried using something like this to sort, but it doesn't return the items in a sorted order.
let sorted = await Sensor.findById(req.params.id).sort({ laps: -1 }).exec();
console.log("sorted", sorted);
} catch (err) {
console.log(err);
}
Again, I'm only trying to sort the students by laps in a certain grade, not all of the students from all classes.
Thanks!
Have you tried:
let sorted = await Sensor.findById(req.params.id).sort({
"students.laps": -1
}).exec();
console.log("sorted", sorted);
}
catch (err) {
console.log(err);
}
I have a column setup with a cell formatter and is working fine.
{ title: "MKT Score", field: "MKTScore", width: 110, hozAlign: "center", formatter: "star", formatterParams: { stars: 3 }, },
what I'm look at trying to do is, if a value of a different cell is false is to hide the Formatter on a cell so it would be blank.
For some situations, such as the "star" formatter, you could pass a function to the formatterParams property in order to manupilate the formatter. Here is an example where, if the bool column is false, show blank:
const dataSet1 = [
{ id: 1, name: 'Billy Bob', bool: false, gender: 'male', rating: 2, col: 'red' },
{ id: 2, name: 'Mary May', bool: true, gender: 'female', rating: 3, col: 'blue' },
{ id: 3, name: 'Christine Lobowski', bool: false, gender: 'female', rating: 0, col: 'green' },
{ id: 4, name: 'Brendon Philips', bool: true, gender: 'male', rating: 2, col: 'orange' },
{ id: 5, name: 'Margret Marmajuke', bool: false, gender: 'female', rating: 0, col: 'yellow' }
]
const table = new Tabulator('#table', {
data: dataSet1,
columns: [
{ title: 'Name', field: 'name' },
{ title: 'Bool', field: 'bool' },
{ title: 'Gender', field: 'gender' },
{ title: 'Rating', field: 'rating', formatter: "star" , formatterParams: stars },
{ title: 'Favourite Color', field: 'col' }
]
})
function stars(row) {
return row.getData().bool ? { stars: 3 } : { stars: -1 }
}
<link href="https://unpkg.com/tabulator-tables#5.1.8/dist/css/tabulator.min.css" rel="stylesheet">
<script type="text/javascript" src="https://unpkg.com/tabulator-tables#5.1.8/dist/js/tabulator.min.js"></script>
<div id="table"></div>
I am working on e-commerce site using nextjs, express, mongoose, nodejs. User has selected items to order. When he wants to view his list, I call the list of items from userSchema. It is list of ordered items which I get in the below given format:
myList: {
createdAt: 2021-03-19T12:03:41.989Z,
isPaid: false,
isDelivered: false,
_id: 605493f4bd3f98bb9bd5366c,
menuId: 3,
userId: 6006018031a53c2d47e01d93,
itemName: 'Masala Khichdi',
itemPrice: 15,
itemSize: 64,
qtty: 2,
itemPic: '/images/food-menu-3#2X.png',
summary: '+918 372 574',
__v: 0
},{
createdAt: 2021-03-19T12:22:23.579Z,
isPaid: false,
isDelivered: false,
_id: 6054c60667a9c2bc7e2522ce,
menuId: 4,
userId: 6006018031a53c2d47e01d93,
itemName: 'Food Menu 4',
itemPrice: 12,
itemSize: 32,
qtty: 1,
itemPic: '/images/food-menu-4#2X.png',
summary: '+123 456 789',
__v: 0
},{
createdAt: 2021-03-19T12:22:23.579Z,
isPaid: false,
isDelivered: false,
_id: 6054c85467a9c2bc7e2522cf,
menuId: 3,
userId: 6006018031a53c2d47e01d93,
itemName: 'Masala Khichdi',
itemPrice: 11,
itemSize: 32,
qtty: 2,
itemPic: '/images/food-menu-3#2X.png',
summary: '+918 372 574',
__v: 0
}
To process further I need to convert the same list to an array as shown below:
myList: [{
createdAt: 2021-03-19T12:03:41.989Z,
isPaid: false,
isDelivered: false,
_id: 605493f4bd3f98bb9bd5366c,
menuId: 3,
userId: 6006018031a53c2d47e01d93,
itemName: 'Masala Khichdi',
itemPrice: 15,
itemSize: 64,
qtty: 2,
itemPic: '/images/food-menu-3#2X.png',
summary: '+918 372 574',
__v: 0
},{
createdAt: 2021-03-19T12:22:23.579Z,
isPaid: false,
isDelivered: false,
_id: 6054c60667a9c2bc7e2522ce,
menuId: 4,
userId: 6006018031a53c2d47e01d93,
itemName: 'Food Menu 4',
itemPrice: 12,
itemSize: 32,
qtty: 1,
itemPic: '/images/food-menu-4#2X.png',
summary: '+123 456 789',
__v: 0
},{
createdAt: 2021-03-19T12:22:23.579Z,
isPaid: false,
isDelivered: false,
_id: 6054c85467a9c2bc7e2522cf,
menuId: 3,
userId: 6006018031a53c2d47e01d93,
itemName: 'Masala Khichdi',
itemPrice: 11,
itemSize: 32,
qtty: 2,
itemPic: '/images/food-menu-3#2X.png',
summary: '+918 372 574',
__v: 0
} ]
How to do this in backend using nodejs
what is your mongoose query? if you are retrieving data according to userId.
Add .toArray() method in your query.
[ { id: 4,
category_id: 7,
user_id: 2,
title: '',
image1: '15717679702861gohz24vrk2262fov.jpg',
image2: '15717679702891gohz24vrk2262fox.jpg',
image3: '15717679702911gohz24vrk2262foz.jpg',
image4: '15717679702921gohz24vrk2262fp0.jpg',
image5: '15717679702931gohz24vrk2262fp1.jpg',
status: 2,
created_at: 2019-10-22T18:12:50.000Z,
updated_at: 2019-10-22T18:12:50.000Z,
item_id: 1,
category_field_id: 4,
value: 'Iphone',
is_title: 1,
is_description: 0 },
{ id: 3,
category_id: 7,
user_id: 2,
title: '',
image1: '15717679702861gohz24vrk2262fov.jpg',
image2: '15717679702891gohz24vrk2262fox.jpg',
image3: '15717679702911gohz24vrk2262foz.jpg',
image4: '15717679702921gohz24vrk2262fp0.jpg',
image5: '15717679702931gohz24vrk2262fp1.jpg',
status: 2,
created_at: 2019-10-22T18:12:50.000Z,
updated_at: 2019-10-22T18:12:50.000Z,
item_id: 1,
category_field_id: 3,
value: 'Other',
is_title: 0,
is_description: 0 },
{ id: 11,
category_id: 7,
user_id: 2,
title: '',
image1: '15718960965161gohz24rzk24acmit.jpg',
image2: '15718960965181gohz24rzk24acmiu.jpg',
image3: '15718960965191gohz24rzk24acmiv.jpg',
image4: '15718960965201gohz24rzk24acmiw.jpg',
image5: '15718960965221gohz24rzk24acmiy.jpg',
status: 0,
created_at: 2019-10-24T05:48:16.000Z,
updated_at: 2019-10-24T05:48:16.000Z,
item_id: 3,
category_field_id: 3,
value: 'Other',
is_title: 0,
is_description: 0 } ]
i want to group by this on item_id. but only those who have a specific length that is enter by user (number of inputs by user in search)
suppose length is 2 so the item that having only two object included in final result;
like
{
1: [{ id: 4,
category_id: 7,
user_id: 2,
title: '',
image1: '15717679702861gohz24vrk2262fov.jpg',
image2: '15717679702891gohz24vrk2262fox.jpg',
image3: '15717679702911gohz24vrk2262foz.jpg',
image4: '15717679702921gohz24vrk2262fp0.jpg',
image5: '15717679702931gohz24vrk2262fp1.jpg',
status: 2,
created_at: 2019-10-22T18:12:50.000Z,
updated_at: 2019-10-22T18:12:50.000Z,
item_id: 1,
category_field_id: 4,
value: 'Iphone',
is_title: 1,
is_description: 0 },
{ id: 3,
category_id: 7,
user_id: 2,
title: '',
image1: '15717679702861gohz24vrk2262fov.jpg',
image2: '15717679702891gohz24vrk2262fox.jpg',
image3: '15717679702911gohz24vrk2262foz.jpg',
image4: '15717679702921gohz24vrk2262fp0.jpg',
image5: '15717679702931gohz24vrk2262fp1.jpg',
status: 2,
created_at: 2019-10-22T18:12:50.000Z,
updated_at: 2019-10-22T18:12:50.000Z,
item_id: 1,
category_field_id: 3,
value: 'Other',
is_title: 0,
is_description: 0 }
]
}
By default, lodash doesn't provide the feature you need.
Instead, you can try combining _groupBy and _pickBy functions.
var groupedItems = _.groupBy(items, 'item_id');
var userSearchLength = 2;
var filteredGrouping = _.pickBy(groupedItems, function(value, key) {
return value.length == userSearchLength;
});
const userInputNumber = 2;
let grouped =_groupBy(obj,(o)=> o.item_id)
Object.keys(grouped).forEach(item_id=> {
if(grouped[item_id].length !== userInputNumber){
delete grouped[item_id];
}
})
You'll have to group first and then check and delete groups which don't have the length of array you desire.
I hope this will help you.
You can first group the data and then filter the data that you needed.
const givenLength = 2;
const groupData =_.groupBy(data,(o)=> o.item_id);
const filtered = _.filter(groupData, (o) => o.length === givenLength );
i am attempting to insert an array
Here is my schema:
/**
* Created by root on 12/4/16.
*/
module.exports = function (mongoose) {
var hotPrice = mongoose.Schema({
days: String,
price: String
});
return mongoose.model('hotPrice', hotPrice);
};
And here is my route:
router.route('/createHot')
.get(function (req, res) {
var values = [
{days: 1, price: "63"},
{days: 2, price: "125"},
{days: 3, price: "185"},
{days: 4, price: "250"},
{days: 5, price: "314"},
{days: 6, price: "375"},
{days: 7, price: "425"},
{days: 8, price: "495"},
{days: 9, price: "560"},
{days: 10, price: "620"}
];
mongoose.models.hotPrice(values).insert(function (err, message) {
res.status(200);
});
});
However i get the following:
TypeError: mongoose.models.hotPrice(...).insert is not a function
Can anyone tell me how i can bulk insert this array?
You can find the answer here: http://mongoosejs.com/docs/api.html#model_Model.create
You can do as follows: (using the example of mongoose docs)
// pass an array
var values = [
{days: 1, price: "63"},
{days: 2, price: "125"},
{days: 3, price: "185"},
{days: 4, price: "250"},
{days: 5, price: "314"},
{days: 6, price: "375"},
{days: 7, price: "425"},
{days: 8, price: "495"},
{days: 9, price: "560"},
{days: 10, price: "620"}
];
YourSchemeObject.create(values, function (err, values) {
if (err) // ...
})
You also can find a similar question here:
How to save an array of objects to mongoose DB with only one call?
Hope it helps.