如何从GWT中的jsarray中删除值? [英] How to delete value from jsarray in GWT?

查看:97
本文介绍了如何从GWT中的jsarray中删除值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题:
1)是否可以使用pop方法删除jsarray中的任何值或只删除最后一个值?
2)我如何从jsarray中删除或删除一个值?有人可以发表一个例子吗?
这样的东西在这里

i have two questions: 1) is it possible to delete any value in jsarray or only the last on with the pop method? 2) how can i remove or delete a value from jsarray? does somebody can post an example. something like this here

public JsArray<MyObject> myObjects = JavaScriptObject.createArray().cast();
myObjects.push(new MyObject("Good"));
myObjects.push(new MyObject("morning"));
myObjects.push(new MyObject("people"));
myObjects.delete(1);

thx很多!

thx a lot!

推荐答案

JavaScript中的数组是稀疏,所以你不能,例如,从它中删除一个对象,并将所有以下内容移动到较低的索引处在Java中,例如 List );至少不会使用一些 remove 方法。

Arrays in JavaScript are sparse, so you cannot, for example, remove an object from it and have all the following be moved up to lower indices (like you'd have in Java with a List for instance); at least not with some remove method.

仅使用GWT Java,您可以将特定索引处的值设置为 null ,但就是这样。

Using only GWT Java, you can set the value at a specific index to null, but that's it.

使用JSNI,您可以删除它(几乎相当于将它设置为 undefined 删除myObjects [1] )或者您可以删除它:

Using JSNI, you can delete it (almost equivalent to setting it to undefined: delete myObjects[1]) or you can remove it:

public static native remove(JsArray<?> arr, int index, int count) /*-{
   arr.splice(index, count);
}-*/;

这篇关于如何从GWT中的jsarray中删除值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆