开发者

Generate UUID with GWT

开发者 https://www.devze.com 2023-01-16 20:06 出处:网络
Is there any way开发者_StackOverflow社区 to generate UUID with GWT?You can generate an UUID in GWT by reusing a Javascript UUID implementation an wrapping it using JSNI:

Is there any way开发者_StackOverflow社区 to generate UUID with GWT?


You can generate an UUID in GWT by reusing a Javascript UUID implementation an wrapping it using JSNI:

public native static String uuid() /*-{
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g,
            function(c) {
                var r = Math.random() * 16 | 0, v = c == 'x' ? r
                        : (r & 0x3 | 0x8);
                return v.toString(16);
            });
}-*/;

If you want just an unique ID (not an UUID) to use in your GWT elements, use:

String id = DOM.createUniqueId();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号