jquery nestable losing drag/drop capability after dynamic loading nestable menu - jquery-nestable
Having trouble after adding the nestable div contents dynamically from a database.
nestable with static data works as expected. I can add items from nestable2 and see the changes in Serialized Output.
nestable with dynamic data
loses the drag/drop capability from nestable2 to nestable, though drag/drop within nestable appears to still work. However, changes are not reflected in Serialized Output.
Further, it appears the dynamic data version of Serialized Output for nestable is not complete. Comparing the nestable Serialized Output between the two links shows that the nestable with dynamic data link's JSON object ends after the Metal category menu, though the full menu is displayed on that page in the nestable div and in the tshoot innerHTML.
Can anyone point me in the right direction to resolve this issue?
Thanks!
Question too vague? OK, let me add more details.
Here's some code that builds the nestable menu from JSON:
...
function buildItem(item) {
var html = "<li class='dd-item' data-id='" + item.id + "' id='" + item.id + "'>";
html += "<div class='dd-handle'>" + item.id + "</div>";
if (item.children) {
html += "<ol class='dd-list'>";
$.each(item.children, function (index, sub) {
html += buildItem(sub);
});
html += "</ol>";
}
html += "</li>";
return html;
}
$.each(JSON.parse(obj), function (index, item) {
$('#nestable2 ul').append(buildItem(item));
});
...
I compared the lists in the hardcoded version with the dynamic version and noticed the good, hardcoded version begins with an ol tag where the dynamic version begins with a ul tag (can't provide the html in this post for some reason). So I changed the code to
...
function buildItem(item) {
var html = "<li class='dd-item' data-id='" + item.id + "'>";
html += "<div class='dd-handle'>" + item.id + "</div>";
if (item.children) {
html += "<ol class='dd-list'>";
$.each(item.children, function (index, sub) {
html += buildItem(sub);
});
html += "</ol>";
}
html += "</li>";
return html;
}
$.each(JSON.parse(obj), function (index, item) {
$('#nestable2 ol').append(buildItem(item));
});
...
and made the nestable2 div start with an ol tag.
That sort of works, but now I get extra children (e.g., Plastic, Valves, Heating and Cooling, In Stock Fixtures and Misc are appended to Metal.
Valves, Heating and Cooling, In Stock Fixtures and Misc are appended to Plastic and In Stock Fixtures and Misc are appended to Heating and Cooling.
So clearly there is an issue with the if (item.children) loop.
Does anyone see the issue and maybe a proposed fix?
Here's the valid JSON:
[{"id":"Metal","children":[{"id":"Propress","children":[{"id":"Elbows","children":[{"id":"1/2 90"},{"id":"1/2 45"},{"id":"3/4 90"},{"id":"3/4 45"},{"id":"1/2 LS 90"},{"id":"1/2 ST 45"}]},{"id":"Tees","children":[{"id":"1/2 x 1/2 x 3/4"},{"id":"1/2"},{"id":"3/4 x 1/2 x 1/2"}]},{"id":"Couplings"}]},{"id":"Copper","children":[{"id":"Elbows","children":[{"id":"1/2 90"},{"id":"1/2 45"},{"id":"3/4 90"},{"id":"3/4 45"},{"id":"1/2 LS 90"},{"id":"1/2 ST 45"}]},{"id":"Tees","children":[{"id":"1/2 x 1/2 x 3/4"},{"id":"1/2"},{"id":"3/4 x 1/2 x 1/2"}]},{"id":"Couplings"}]},{"id":"Black","children":[{"id":"Elbows","children":[{"id":"1/2 90"},{"id":"1/2 45"},{"id":"3/4 90"},{"id":"3/4 45"},{"id":"1/2 LS 90"},{"id":"1/2 ST 45"}]},{"id":"Tees","children":[{"id":"1/2 x 1/2 x 3/4"},{"id":"1/2"},{"id":"3/4 x 1/2 x 1/2"}]},{"id":"Couplings"}]},{"id":"Brass","children":[{"id":"Elbows","children":[{"id":"1/2 90"},{"id":"1/2 45"},{"id":"3/4 90"},{"id":"3/4 45"},{"id":"1/2 LS 90"},{"id":"1/2 ST 45"}]},{"id":"Tees","children":[{"id":"1/2 x 1/2 x 3/4"},{"id":"1/2"},{"id":"3/4 x 1/2 x 1/2"}]},{"id":"Couplings"}]},{"id":"Cast Iron","children":[{"id":"Elbows","children":[{"id":"1/2 90"},{"id":"1/2 45"},{"id":"3/4 90"},{"id":"3/4 45"},{"id":"1/2 LS 90"},{"id":"1/2 ST 45"}]},{"id":"Tees","children":[{"id":"1/2 x 1/2 x 3/4"},{"id":"1/2"},{"id":"3/4 x 1/2 x 1/2"}]},{"id":"Couplings"}]},{"id":"Megapress","children":[{"id":"Elbows","children":[{"id":"1/2 90"},{"id":"1/2 45"},{"id":"3/4 90"},{"id":"3/4 45"},{"id":"1/2 LS 90"},{"id":"1/2 ST 45"}]},{"id":"Tees","children":[{"id":"1/2 x 1/2 x 3/4"},{"id":"1/2"},{"id":"3/4 x 1/2 x 1/2"}]},{"id":"Couplings"}]}]},{"id":"Plastic","children":[{"id":"Pipe","children":[{"id":"PVC"},{"id":"PEX"},{"id":"Aquatherm"}]},{"id":"PVC","children":[{"id":"Elbows","children":[{"id":"1/2 90"},{"id":"1/2 45"},{"id":"3/4 90"},{"id":"3/4 45"},{"id":"1/2 LS 90"},{"id":"1/2 ST 45"}]},{"id":"Tees","children":[{"id":"1/2 x 1/2 x 3/4"},{"id":"1/2"},{"id":"3/4 x 1/2 x 1/2"}]},{"id":"Flanges"},{"id":"Couplings"},{"id":"Caps"},{"id":"Unions"},{"id":"Reducers"},{"id":"Adapters"},{"id":"Valves"}]},{"id":"PEX","children":[{"id":"Elbows","children":[{"id":"1/2 90"},{"id":"1/2 45"},{"id":"3/4 90"},{"id":"3/4 45"},{"id":"1/2 LS 90"},{"id":"1/2 ST 45"}]},{"id":"Tees","children":[{"id":"1/2 x 1/2 x 3/4"},{"id":"1/2"},{"id":"3/4 x 1/2 x 1/2"}]},{"id":"Flanges"},{"id":"Couplings"},{"id":"Caps"},{"id":"Unions"},{"id":"Reducers"},{"id":"Adapters"},{"id":"Valves"}]},{"id":"Aquatherm","children":[{"id":"Elbows","children":[{"id":"1/2 90"},{"id":"1/2 45"},{"id":"3/4 90"},{"id":"3/4 45"},{"id":"1/2 LS 90"},{"id":"1/2 ST 45"}]},{"id":"Tees","children":[{"id":"1/2 x 1/2 x 3/4"},{"id":"1/2"},{"id":"3/4 x 1/2 x 1/2"}]},{"id":"Flanges"},{"id":"Couplings"},{"id":"Caps"},{"id":"Unions"},{"id":"Reducers"},{"id":"Adapters"},{"id":"Valves"}]}]},{"id":"Valves"},{"id":"Heating and Cooling","children":[{"id":"Radiant","children":[{"id":"Tubing","children":[{"id":"1/2 PEX"},{"id":"3/4 PEX"}]},{"id":"Manifolds"},{"id":"Heads"},{"id":"Valves"},{"id":"Fittings"}]},{"id":"Thermostats"},{"id":"Waterheaters"},{"id":"Pumps/Valves"},{"id":"Boilers"},{"id":"MiniSplits"}]},{"id":"In Stock Fixtures"},{"id":"Misc"}]
The JSON seen in the new Serialized Output has:
... {"id":"1/2 ST 45"},{"id":"Plastic","children":[{"id":"Pipe" ...
while the valid JSON has:
... {"id":"1/2 ST 45"}]},{"id":"Tees","children":[{"id":"1/2 x 1/2 x 3/4"} ..
Note that new Serialized Output is missing the ']}' after {"id":"1/2 ST 45"}
TIA.
Related
Maxima. How to prevent degree calculations
Is it possible for all calculations in the expression for numbers in a power to be prevented? Perhaps by pre-processing the expression or adding tellsimp rules? Or some other way? For example, to distrib (10 ^ 10 * (x + 1)); which produces: 1000000000 x + 1000000000 instead issued: 10 ^ 10 * x + 10 ^ 10 And similarly factor (10 ^ 10 * x + 10 ^ 10); returned: 10 ^ 10 * (x + 1); Just as factor(200); 2^3*5^2 represents power of numbers, only permanently?
Interesting question, although I don't see a good solution. Here's something I tried as an experiment, which is to display integers in factored form. I am working with Maxima 5.44.0 + SBCL. (%i1) :lisp (defun integer-formatter (x) ($factor x)) INTEGER-FORMATTER (%i1) :lisp (setf (get 'integer 'formatter) 'integer-formatter) INTEGER-FORMATTER (%i1) (x + 1000)^3; 3 3 3 (%o1) (x + 2 5 ) (%i2) 10^10*(x + 1); 2 5 2 5 (%o2) (2 5 ) (x + 1) This is only a modification of the display; the internal representation is just a single integer. (%i3) :lisp $% ((MTIMES SIMP) 10000000000 ((MPLUS SIMP) 1 $X)) That seems kind of clumsy, since e.g. 2^(2*5)*5^(2*5) isn't really more comprehensible than 10000000000. A separate question is whether the arithmetic on 10^10 could be suppressed, so it actually stays as 10^10 and isn't represented internally as 10000000000. I'm pretty sure that would be difficult. Unfortunately Maxima is not too good with retracting identities which are applied, particularly with the built-in identities which are applied to perform arithmetic and other operations.
How do you add spaces in front of 'y' integers in a nested loop?
for x in range(1, 4): print(x) for y in range(5, 10): print(y) I tried adding " " + in front of y within print. Essentially, print(" " + y) I tried creating a string w that equals " " to add in front of y. Essentially, w = " " print(w + y) I'd like the output to look like: 1 5 6 2 5 6 3 5 6 I'm exploring .join() at the moment to see if this method can provide a solution. Thank you.
for x in range(1, 4): print(x) for y in range(5, 10): w = " " print(w + str(y)) or print(" " + str(y)) output: 1 5 6 2 5 6
Python string formatting is easy and clean in this case. You can see https://pyformat.info/ for a quick introduction. Example with the most recent format function: for x in range(1, 4): print("{:d}".format(x)) for y in range(5, 10): print("{:>3d}".format(y)) Short explanation: {:d}: format the argument as a digit {:>3d}: align right, make the string 3 characters long and format the argument as a digit
How do I find the amount of levels in an Octree if I have N nodes?
If the octree level is 0, then I have 8 nodes. Now, if the octree level is 1, then I have 72 nodes. But if I have (for example) 500 nodes, how do I calculate what the level would be?
To calculate the max number of nodes at level n you would calculate: 8**1 + 8**2 + 8**3 ... 8**n So at level 2, that's 8 + 64 This can be generalized as: ((8 ** (h + 1)) - 1)/7 - 1 In javascript you might write: function maxNodes(h){ return ((8 ** (h + 1)) - 1)/7 - 1 } for (let i = 1; i < 4; i++){ console.log(maxNodes(i)) } To find the inverse you will need to use Log base 8 and some algebra and you'll arrive at a formula: floor (log(base-8)(7 * n + 1)) In some languages like python you can calculate math.floor(math.log(7*n + 1, 8)), but javascript doesn't have logs to arbitrary bases so you need to depend on the identity: Log(base-b)(n) == Log(n)/Log(b) and calculate something like: function height(n){ return Math.floor(Math.log(7 * n + 1)/Math.log(8)) } console.log(height(8)) console.log(height(72)) // last on level 2 console.log(height(73)) // first on level 3 console.log(height(584)) // last on level 3 console.log(height(585)) // first on level 4
q/KDB - nprev function to get all the previous n elements
I am struggling to write a nprev function in KDB; xprev function returns the nth element but I need all the prev n elements relative to the current element. q)t:([] i:1+til 26; s:.Q.a) q)update xp:xprev[3;]s,p:prev s from t Any help is greatly appreciated.
You can achieve the desired result by applying prev repeatedly and flipping the result q)n:3 q)select flip 1_prev\[n;s] from t s ----- " " "a " "ba " "cba" "dcb" "edc" .. If n is much smaller than the rows count, this will be faster than some of the more straightforward solutions.
The xprev function basically looks like this : xprev1:{y til[count y]-x} //readable xprev We can tweak it to get all n elements nprev:{y til[count y]-\:1+til x} using nprev in the query q)update np: nprev[3;s] , xp1:xprev1[3;s] , xp: xprev[3;s], p:prev[s] from t i s np xp1 xp p ------------------- 1 a " " 2 b "a " a 3 c "ba " b 4 d "cba" a a c 5 e "dcb" b b d 6 f "edc" c c e k equivalent of nprev k)nprev:{$[0h>#y;'`rank;y(!#y)-\:1+!x]} and similarly nnext would look like k)nnext:{$[0h>#y;'`rank;y(!#y)+\:1+!x]}
VFP Unit Matrix Multiply problem on the iPhone
I'm trying to write a Matrix3x3 multiply using the Vector Floating Point on the iPhone, however i'm encountering some problems. This is my first attempt at writing any ARM assembly, so it could be a faily simple solution that i'm not seeing. I've currently got a small application running using a maths library that i've written. I'm investigating into the benifits using the Vector Floating Point Unit would provide so i've taken my matrix multiply and converted it to asm. Previously the application would run without a problem, however now my objects will all randomly disappear. This seems to be caused by the results from my matrix multiply becoming NAN at some point. Heres the code IMatrix3x3 operator*(IMatrix3x3 & _A, IMatrix3x3 & _B) { IMatrix3x3 C; //C++ code for the simulator #if TARGET_IPHONE_SIMULATOR == true C.A0 = _A.A0 * _B.A0 + _A.A1 * _B.B0 + _A.A2 * _B.C0; C.A1 = _A.A0 * _B.A1 + _A.A1 * _B.B1 + _A.A2 * _B.C1; C.A2 = _A.A0 * _B.A2 + _A.A1 * _B.B2 + _A.A2 * _B.C2; C.B0 = _A.B0 * _B.A0 + _A.B1 * _B.B0 + _A.B2 * _B.C0; C.B1 = _A.B0 * _B.A1 + _A.B1 * _B.B1 + _A.B2 * _B.C1; C.B2 = _A.B0 * _B.A2 + _A.B1 * _B.B2 + _A.B2 * _B.C2; C.C0 = _A.C0 * _B.A0 + _A.C1 * _B.B0 + _A.C2 * _B.C0; C.C1 = _A.C0 * _B.A1 + _A.C1 * _B.B1 + _A.C2 * _B.C1; C.C2 = _A.C0 * _B.A2 + _A.C1 * _B.B2 + _A.C2 * _B.C2; //VPU ARM asm for the device #else //create a pointer to the Matrices IMatrix3x3 * pA = &_A; IMatrix3x3 * pB = &_B; IMatrix3x3 * pC = &C; //asm code asm volatile( //turn on a vector depth of 3 "fmrx r0, fpscr \n\t" "bic r0, r0, #0x00370000 \n\t" "orr r0, r0, #0x00020000 \n\t" "fmxr fpscr, r0 \n\t" //load matrix B into the vector bank "fldmias %1, {s8-s16} \n\t" //load the first row of A into the scalar bank "fldmias %0!, {s0-s2} \n\t" //calulate C.A0, C.A1 and C.A2 "fmuls s17, s8, s0 \n\t" "fmacs s17, s11, s1 \n\t" "fmacs s17, s14, s2 \n\t" //save this into the output "fstmias %2!, {s17-s19} \n\t" //load the second row of A into the scalar bank "fldmias %0!, {s0-s2} \n\t" //calulate C.B0, C.B1 and C.B2 "fmuls s17, s8, s0 \n\t" "fmacs s17, s11, s1 \n\t" "fmacs s17, s14, s2 \n\t" //save this into the output "fstmias %2!, {s17-s19} \n\t" //load the third row of A into the scalar bank "fldmias %0!, {s0-s2} \n\t" //calulate C.C0, C.C1 and C.C2 "fmuls s17, s8, s0 \n\t" "fmacs s17, s11, s1 \n\t" "fmacs s17, s14, s2 \n\t" //save this into the output "fstmias %2!, {s17-s19} \n\t" //set the vector depth back to 1 "fmrx r0, fpscr \n\t" "bic r0, r0, #0x00370000 \n\t" "orr r0, r0, #0x00000000 \n\t" "fmxr fpscr, r0 \n\t" //pass the inputs and set the clobber list : "+r"(pA), "+r"(pB), "+r" (pC) : :"cc", "memory","s0", "s1", "s2", "s8", "s9", "s10", "s11", "s12", "s13", "s14", "s15", "s16", "s17", "s18", "s19" ); #endif return C; } As far as i can see that makes sence. While debugging i've managed to notice that if i were to say _A = C prior to the return and after the ASM, _A will not necessarily be equal to C which has only increased my confusion. I had thought it was possibly due to the pointers I'm giving to the VFPU being incrimented by lines such as "fldmias %0!, {s0-s2} \n\t" however my understanding of asm is not good enough to properly understand the problem, nor to see an alternative approach to that line of code. Anyway, I was hoping someone with a greater understanding than me would be able to see a solution, and any help would be greatly appreciated, thank you :-) Edit: I've found that pC seems to be NULL when the asm code is hit despite being set pC = &C. I'm assuming this is due to the compiler rearranging the code in a manor thats breaking it? I've tried the various methods I've seen for stopping this happening (like adding everything relevent in the input list - thought this shouldnt even be nessisary since i'm listing "memory" in the clobber list) and I'm still getting the same problems. Edit #2: Right, the memory issue seems to have been caused by me not including "r0" in the clobber list, however fixing that (if it is indeed fixed) doesnt seem to have fixed the problem. I noticed that multiplying a rotation matrix by the identity matrix doesn't work correctly and instead gives 0.88 as the last entry in the matrix instead of 1: | 0.88 0.48 0 | | 1 0 0 | | 0.88 0.48 0 | |-0.48 0.88 0 | * | 0 1 0 | = |-0.48 0.88 0 | | 0 0 1 | | 0 0 1 | | 0 0 0.88| I figured then that my logic must be wrong somewhere so i stepped through the assembly. everything seems fine up until the last "fmacs s17, s14, s2 \n\t" where: s0 = 0 s14 = 0 s17 = 0 s1 = 0 s15 = 0 s18 = 0 s2 = 1 s16 = 1 s19 = 0 so surely the fmacs is performing the operation: s17 = s17 + s14 * s2 = 0 + 0 * 1 = 0 s18 = s18 + s15 * s2 = 0 + 0 * 1 = 0 s19 = s19 + s16 * s2 = 0 + 1 * 1 = 1 However the result gives s19 = 0.88 which has left me even more confused :S am i misunderstanding how fmacs works? (P.S sorry for what has now become a really long question :-P)
Solved the problem! i was unaware that the vector banks were "circular". The banks 0-7, 8-15, 16-23 and 24-31 can contain vectors of up to a length of 8, and can be used as vectors by simply stating you are using s16 with a length of 4 for example. However, in my case i had been using s14 with a length of 3, assuming this would get me s14,s15 and s16, but instead because its circular it would roll back to s8 - in other words i was using s14, s15 and s8. Took my a long time to see that, so hopefully if anyone else has a similar problem they will find this :-)