如何访问从电梯调用返回的数组

发布于 2024-10-12 22:11:07 字数 1449 浏览 1 评论 0原文

我正在尝试为 Comet 回调生成一些 Javascript。我的代码可以工作,但需要使用几个实际上不需要的附加变量。问题是我不确定如何访问从 通话

JsCrVar("node" + c.id, Call("dataTable.fnAddData",
        JsArray(Text(c.name),
                Text(c.initials),
                makeDeleteButton(c)),
        Num(0))) &
JsCrVar("row" + c.id, Call("dataTable.fnGetNodes", JsVar("node" + c.id + "[0]"))) &
SetExp(JsVar("row" + c.id + ".id"), Str(c.id.toString))

这会生成如下 JavaScript(为了便于阅读而缩进):

var node2 = dataTable.fnAddData(["Test User",
                                 "TU",
                                 "<button onclick=\"liftAjax.lift_ajaxHandler(&quot;F306228675550KFT=true&quot;, null, null, null); return false;\">delete</button>"]
                                 ,0);
var row2 = dataTable.fnGetNodes(node2[0]);
row2.id = "2";

我想要生成的代码如下:

dataTable.fnGetNodes(dataTable.fnAddData(["Test User",
                                 "TU",
                                 "<button onclick=\"liftAjax.lift_ajaxHandler(&quot;F306228675550KFT=true&quot;, null, null, null); return false;\">delete</button>"]
                                 ,0)[0]).id = "2";

如何

  1. 从返回的数组中获取第 0 个元素?
  2. 从返回的对象中获取子元素“id”?

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 Call.

JsCrVar("node" + c.id, Call("dataTable.fnAddData",
        JsArray(Text(c.name),
                Text(c.initials),
                makeDeleteButton(c)),
        Num(0))) &
JsCrVar("row" + c.id, Call("dataTable.fnGetNodes", JsVar("node" + c.id + "[0]"))) &
SetExp(JsVar("row" + c.id + ".id"), Str(c.id.toString))

This generates JavaScript like follows (indented for readability):

var node2 = dataTable.fnAddData(["Test User",
                                 "TU",
                                 "<button onclick=\"liftAjax.lift_ajaxHandler("F306228675550KFT=true", null, null, null); return false;\">delete</button>"]
                                 ,0);
var row2 = dataTable.fnGetNodes(node2[0]);
row2.id = "2";

The code that I would like to generate is as follows:

dataTable.fnGetNodes(dataTable.fnAddData(["Test User",
                                 "TU",
                                 "<button onclick=\"liftAjax.lift_ajaxHandler("F306228675550KFT=true", null, null, null); return false;\">delete</button>"]
                                 ,0)[0]).id = "2";

How does one

  1. Get the 0th element from the returned array?
  2. Get the sub-element 'id' from that returned object?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

離人涙 2024-10-19 22:11:07

我认为您必须创建自己的自定义类来返回从 Call 返回的数组的第 n 个成员。尝试这样的事情:

case class JsRetArray(array: JsExp, n: Int) extends JsExp {
  def toJsCmd = array.toJsCmd + "[" + n + "]"
}

然后你可以这样做:

Call("dataTable.fnGetNodes",
    JsRetArray(Call("dataTable.fnAddData",
                    JsArray(Text(c.name),
                            Text(c.initials),
                            makeDeleteButton(c)),
                    Num(0)),
               0)
    ) ~> Id === 2

当使用 .toJsCmd 调用时,会产生:

dataTable.fnGetNodes(dataTable.fnAddData(["Test User", 
                                         "TU", 
                                         "<button onclick=\"liftAjax.lift_ajaxHandler("F306228675550KFT=true", null, null, null); return false;\">delete</button>"]
                   ,0)[0]).id = 2

I think you'll have to create your own custom class to return the n'th member of an array that's returned from Call. Try something like this:

case class JsRetArray(array: JsExp, n: Int) extends JsExp {
  def toJsCmd = array.toJsCmd + "[" + n + "]"
}

Then you can do:

Call("dataTable.fnGetNodes",
    JsRetArray(Call("dataTable.fnAddData",
                    JsArray(Text(c.name),
                            Text(c.initials),
                            makeDeleteButton(c)),
                    Num(0)),
               0)
    ) ~> Id === 2

which, when called with a .toJsCmd, yields:

dataTable.fnGetNodes(dataTable.fnAddData(["Test User", 
                                         "TU", 
                                         "<button onclick=\"liftAjax.lift_ajaxHandler("F306228675550KFT=true", null, null, null); return false;\">delete</button>"]
                   ,0)[0]).id = 2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文