如何访问从电梯调用返回的数组
我正在尝试为 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("F306228675550KFT=true", 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("F306228675550KFT=true", null, null, null); return false;\">delete</button>"]
,0)[0]).id = "2";
如何
- 从返回的数组中获取第 0 个元素?
- 从返回的对象中获取子元素“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
- Get the
0
th element from the returned array? - Get the sub-element 'id' from that returned object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您必须创建自己的自定义类来返回从 Call 返回的数组的第 n 个成员。尝试这样的事情:
然后你可以这样做:
当使用
.toJsCmd
调用时,会产生: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:
Then you can do:
which, when called with a
.toJsCmd
, yields: