Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to access an array returned from a lift call
    primarykey
    data
    text
    <p>I am trying to generate some Javascript for a Comet callback. The code that I have works, but needs to use several additional variables that should not really be required. The problem is that I am not sure how to access an element in an array that is returned from a <a href="http://scala-tools.org/mvnsites/liftweb-2.2/framework/scaladocs/net/liftweb/http/js/JE/Call.html" rel="nofollow">Call</a>.</p> <pre><code>JsCrVar("node" + c.id, Call("dataTable.fnAddData", JsArray(Text(c.name), Text(c.initials), makeDeleteButton(c)), Num(0))) &amp; JsCrVar("row" + c.id, Call("dataTable.fnGetNodes", JsVar("node" + c.id + "[0]"))) &amp; SetExp(JsVar("row" + c.id + ".id"), Str(c.id.toString)) </code></pre> <p>This generates JavaScript like follows (indented for readability):</p> <pre><code>var node2 = dataTable.fnAddData(["Test User", "TU", "&lt;button onclick=\"liftAjax.lift_ajaxHandler(&amp;quot;F306228675550KFT=true&amp;quot;, null, null, null); return false;\"&gt;delete&lt;/button&gt;"] ,0); var row2 = dataTable.fnGetNodes(node2[0]); row2.id = "2"; </code></pre> <p>The code that I would like to generate is as follows:</p> <pre><code>dataTable.fnGetNodes(dataTable.fnAddData(["Test User", "TU", "&lt;button onclick=\"liftAjax.lift_ajaxHandler(&amp;quot;F306228675550KFT=true&amp;quot;, null, null, null); return false;\"&gt;delete&lt;/button&gt;"] ,0)[0]).id = "2"; </code></pre> <p>How does one</p> <ol> <li>Get the <code>0</code>th element from the returned array?</li> <li>Get the sub-element 'id' from that returned object?</li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload