Create hierarchical class structure , loop through data table and then add parent and child and return object
Tag : chash , By : Si Gardner
Date : March 29 2020, 07:55 AM
wish help you to fix your issue Here is an example on how to do that using LINQ. First a sampe datatable. I assume that top-level items have a parent ID of 0. var dataTable = new DataTable();
dataTable.Columns.Add("Id", typeof(Int32));
dataTable.Columns.Add("ParentId", typeof(Int32));
dataTable.Columns.Add("Name", typeof(String));
dataTable.Rows.Add(new Object[] { 1, 0, "A" });
dataTable.Rows.Add(new Object[] { 2, 1, "B" });
dataTable.Rows.Add(new Object[] { 3, 1, "C" });
dataTable.Rows.Add(new Object[] { 4, 0, "D" });
dataTable.Rows.Add(new Object[] { 5, 4, "E" });
class Item {
public Int32 Id { get; set; }
public String Name { get; set; }
public IEnumerable<Item> Children { get; set; }
}
IEnumerable<DataRow> GetChildren(DataTable dataTable, Int32 parentId) {
return dataTable
.Rows
.Cast<DataRow>()
.Where(row => row.Field<Int32>("ParentId") == parentId);
}
Item CreateItem(DataTable dataTable, DataRow row) {
var id = row.Field<Int32>("Id");
var name = row.Field<String>("Name");
var children = GetChildren(dataTable, id)
.Select(r => CreateItem(dataTable, r))
.ToList();
return new Item { Id = id, Name = name, Children = children };
}
IEnumerable<DataRow> GetTopLevelRows(DataTable dataTable) {
return dataTable
.Rows
.Cast<DataRow>()
.Where(row => row.Field<Int32>("ParentId") == 0);
}
var items = GetTopLevelRows(dataTable)
.Select(row => CreateItem(dataTable, row))
.ToList();
|
Is there built-in data structure in clojure supporting both duplicated elements and O(1) removing?
Date : March 29 2020, 07:55 AM
hope this fix your issue A map of values to their "count" ? (Removing a value would be decreasing the counter ?)
|
After removing parent elements cant get again them
Tag : jquery , By : nickthecook
Date : March 29 2020, 07:55 AM
like below fixes the issue You're removing the element that contains your text and input and not just the text and input itself. The parent element is needed to be populated by the text and input. $(function(){
$('#add').click(function(){
var myWritting = $('#textarea').val();
$('#textarea').val('');
$('#content').append( '<p>' + myWritting +'<input type="submit" value="delete" class="hide"/></p>')
});
$('body').on('click', '.hide', function() {
$(this).parent().remove();
return false;
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="add">Add</button>
<textarea id="textarea"></textarea>
<div id="content"></div>
|
Are there any side effects for C code using data structure allocated using operator new
Tag : cpp , By : WuJanJai
Date : March 29 2020, 07:55 AM
hop of those help? Memory is memory, it doesn't really matter which allocator provided it, as long as it's correctly aligned and allocation and deallocation functions are correctly matched (and the structure definition is the same). There should be no problem.
|
How to structure/manipulate data before a POST or after a GET request using Effects
Date : March 29 2020, 07:55 AM
I hope this helps you . In the functions/services that make the HTTP requests. Your application state has a model, if your API requests another state, then it's ouside of your application scope : you just have to make mappers that will convert your application state to the model expected by the server.
|