nested

Convert array of flat objects to nested objects

这一生的挚爱 提交于 2020-03-20 03:43:59
问题 I have the following array (that's actually coming from a backend service): const flat: Item[] = [ { id: 'a', name: 'Root 1', parentId: null }, { id: 'b', name: 'Root 2', parentId: null }, { id: 'c', name: 'Root 3', parentId: null }, { id: 'a1', name: 'Item 1', parentId: 'a' }, { id: 'a2', name: 'Item 1', parentId: 'a' }, { id: 'b1', name: 'Item 1', parentId: 'b' }, { id: 'b2', name: 'Item 2', parentId: 'b' }, { id: 'b2-1', name: 'Item 2-1', parentId: 'b2' }, { id: 'b2-2', name: 'Item 2-2',

Convert array of flat objects to nested objects

旧街凉风 提交于 2020-03-20 03:43:15
问题 I have the following array (that's actually coming from a backend service): const flat: Item[] = [ { id: 'a', name: 'Root 1', parentId: null }, { id: 'b', name: 'Root 2', parentId: null }, { id: 'c', name: 'Root 3', parentId: null }, { id: 'a1', name: 'Item 1', parentId: 'a' }, { id: 'a2', name: 'Item 1', parentId: 'a' }, { id: 'b1', name: 'Item 1', parentId: 'b' }, { id: 'b2', name: 'Item 2', parentId: 'b' }, { id: 'b2-1', name: 'Item 2-1', parentId: 'b2' }, { id: 'b2-2', name: 'Item 2-2',

Nested dropdowns in materialize

倾然丶 夕夏残阳落幕 提交于 2020-03-14 11:07:58
问题 Is it possible to make nested dropdowns in materialize? second dropdown should be on right side <a class='dropdown-button btn' href='#' data-activates='dropdown1' data-beloworigin="true">Drop Me!</a> <ul id='dropdown1' class='dropdown-content'> <li><a class='dropdown-button d' href='#' data-activates='dropdown2' data-hover="hover" data-alignment="right">Drop Me!</a></li> <li><a href="#!">two</a></li> <li><a href="#!">three</a></li> </ul> <ul id='dropdown2' class='dropdown-content'> <li><a

Nested dropdowns in materialize

倖福魔咒の 提交于 2020-03-14 11:07:31
问题 Is it possible to make nested dropdowns in materialize? second dropdown should be on right side <a class='dropdown-button btn' href='#' data-activates='dropdown1' data-beloworigin="true">Drop Me!</a> <ul id='dropdown1' class='dropdown-content'> <li><a class='dropdown-button d' href='#' data-activates='dropdown2' data-hover="hover" data-alignment="right">Drop Me!</a></li> <li><a href="#!">two</a></li> <li><a href="#!">three</a></li> </ul> <ul id='dropdown2' class='dropdown-content'> <li><a

Fill a nested structure with values from a linear supply stream

微笑、不失礼 提交于 2020-02-28 18:46:07
问题 I got stuck in the resolution of the next problem: Imagine we have an array structure, any structure, but for this example let's use: [ [ [1, 2], [3, 4], [5, 6] ], [ 7, 8, 9, 10 ] ] For convenience, I transform this structure into a flat array like: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] Imagine that after certain operations our array looks like this: [ 1, 2, 3, 4, 12515, 25125, 12512, 8, 9, 10] NOTE: those values are a result of some operation, I just want to point out that is independent from

JQuery: Get tag content excluding nested tags

断了今生、忘了曾经 提交于 2020-02-27 23:57:12
问题 I've got some HTML like the following: <span id="A">Text I'm interested in <span id="B">Other crap I don't care about</span> </span> I'm looking to get the text content of span "A" excluding any nested tags (i.e. the content of span "B" in the above example). I'm trying to get the text content, not the HTML content. Also, in my particular case, I know there will always be some text inside of span A prior to any other tags, but I'm interested in the less-constrained solution as well. The

JQuery: Get tag content excluding nested tags

痴心易碎 提交于 2020-02-27 23:49:13
问题 I've got some HTML like the following: <span id="A">Text I'm interested in <span id="B">Other crap I don't care about</span> </span> I'm looking to get the text content of span "A" excluding any nested tags (i.e. the content of span "B" in the above example). I'm trying to get the text content, not the HTML content. Also, in my particular case, I know there will always be some text inside of span A prior to any other tags, but I'm interested in the less-constrained solution as well. The

nested function change variable in an outside function not working

你离开我真会死。 提交于 2020-02-24 12:38:32
问题 def some_func(a): def access_a(): print(a) access_a() outputs the value of a . However, if I want to change a in the nested function like this: def some_func(a): def change_a(): a += 1 print(a) change_a() it raises UnboundLocalError exception. I know a is a nonlocal variable, but why can I access it without declaring nonlocal a ? 回答1: Python scoping rules 101: a name bound in a function body is considered local unless explicitely declared global (Python 2.x and 3.x) or nonlocal (Python 3.x

Generify transformation of hierarchical array into a flat array

自古美人都是妖i 提交于 2020-02-24 10:22:08
问题 I'm trying to generify the transformation of a hierarchical array into a flat array. I have this kind of object which has children of the same type, which has children of the same type etc.. [{ id: "123", children: [ { id: "603", children: [ { id: "684", children: [ ... ] }, { id: "456", children: [] } ] } ] }] I found a way to flatten it and I have the information of the number of nested levels. One level deep (works): let result = myArray.flat() .concat(myArray.flatMap(comm => comm.children

Swift - Encode and Decode a dictionary [String:Any] into plist

耗尽温柔 提交于 2020-02-16 07:29:07
问题 I am trying to store the dictionary in my class Marker but it is throwing an error saying it is not encodable or decodable. I can see the error is caused by the [String: Any] but how can I go around it? var buttonActions : [String: [String: [String:Any]]] = [:] Save and Load func saveData() { let dataFilePath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.appendingPathComponent("\(fileName).plist") let encoder = PropertyListEncoder() do { let data = try