Entity Framework 6: Adding child object to parent's list vs. setting child's navigation property to parent
Tag : chash , By : user180941
Date : March 29 2020, 07:55 AM
Hope this helps Yes, the two approaches are interchangeable. This allows you to create and save your object graph to the database from either the perspective of the MailServer or the MailDomain. If you do code-first, you have the option of removing the properties and mappings if they're not needed.
|
XML parent child structure from flat list
Date : March 29 2020, 07:55 AM
Any of those help Something like this might work for you. Has no error checking on the levels (will break if there's a "level 4" with no previous "level 3"). Sub Tester()
Dim d, doc, root, lvl As Long, r, el, id
Dim parents(0 To 20) 'handle up to 20 levels...
Set doc = New MSXML2.DOMDocument
Set root = doc.createElement("root")
doc.appendChild root
Set parents(0) = root 'Parent node for all "Level 1" nodes...
d = Range("a1").CurrentRegion.Value
For r = LBound(d, 1) To UBound(d, 1)
lvl = CLng(Split(d(r, 1), " ")(1)) 'get level
Set el = doc.createElement("section")
el.setAttribute "ident", d(r, 2)
parents(lvl - 1).appendChild el
Set parents(lvl) = el ' Make this the current Parent node for
' any nodes directly below
Next r
Debug.Print PrettyPrintXML(doc.XML)
End Sub
|
React Native navigation for child components in flat list
Date : March 29 2020, 07:55 AM
wish of those help Im pretty new in React Native (and Javscript) and im trying to understand react native navigation. , You can do it as following. render() {
return (
// <List>
<FlatList
data={this.state.data}
renderItem={({ item }) => (
<CardComponent
navigation={this.props.navigation}
eventname={'Halloween'}
eventveranstalter={'park'}
eventuhr={'17:00'}
eventort={'berlin'}
eventimage={'http://whatstonightapp.com/wp-content/uploads/2016/12/background_light-1.jpg'}
eventtag1={'party'}
eventtag2={'music'}
eventtag3={'dance'}
>
</CardComponent>
)}
|
Need to convert list of data into list of list based on parent child relationship
Date : March 29 2020, 07:55 AM
it should still fix some issue For representing the tree structure, I have used an ArrayList, where the index of the node is equal to its index in the array + 1. If you have a sparse tree/some indices might be missing, use an equivalent approach with a map instead. Solution using Java 8 stream API: public static void main( String[] args ) {
List<ResponseData> responseDataList = Arrays.asList(
new ResponseData( 1, -1 ), // changed null to -1 as null can't be a map key
new ResponseData( 2, 1 ),
new ResponseData( 3, 1 ),
new ResponseData( 4, 1 ),
new ResponseData( 5, 2 ),
new ResponseData( 6, 2 ),
new ResponseData( 7, 3 ),
new ResponseData( 8, 3 ),
new ResponseData( 9, 4 ),
new ResponseData( 10, 4 ),
new ResponseData( 11, 5 ),
new ResponseData( 12, -1 ),
new ResponseData( 13, 12 )
);
final Map<Integer, List<ResponseData>> map = responseDataList.stream()
.collect( Collectors.groupingBy( o -> getLevel( responseDataList, o, 0 ) ) );
System.out.println( map );
// To convert the Map to a List of Lists:
System.out.println( new ArrayList<>( map.values() ));
}
private static int getLevel(List<ResponseData> nodes, ResponseData responseData, int level) {
if( responseData.parent == -1 ) {
return level;
} else {
return getLevel( nodes, nodes.get( responseData.parent - 1 ), level + 1 ); // -1 to adjust index
}
}
private static final class ResponseData {
public int id;
public int parent;
public ResponseData( int id, int parent ) {
this.id = id;
this.parent = parent;
}
@Override
public String toString() {
return String.format( "{id: %d, parent: %d}", id, parent );
}
}
|
convert a flat list into a tree with limited number of nodes per depth
Tag : java , By : Nick Pegg
Date : March 29 2020, 07:55 AM
|