gwt - How to use javascript to store variables to window correctly? -
i trying utilize jsni (gwt's javacript interface) set/get variable to/from js object:window this:
private final native <t> t get(string key)/*-{ homecoming $wnd.key; }-*/; private final native void set(string key, object value)/*-{ $wnd.key = value; }-*/; ///// js equivalent should this
function get(string key){ homecoming window.key; } function set(string key, var value){ window.key = value; } and if set variable: var_1 window:
var var_1={"id":"id_1","name":"name_1"} set("key_1",var_1) then
get("key_1") i var_1 correctly
and set variable var_2 window
var var_2={"id":"id_2","name":"name_2"} set("key_2",var_2) then,try key_1 again
get("key_1") unexpectedly,var_2 returned
so,the problem obvious:the get() function homecoming lastly set variable no matter key is.questions are:
1,why? 2,how create right?
after changing to
private final native <t> t get(string key)/*-{ homecoming $wnd[key]; }-*/; private final native void set(string key, object value)/*-{ $wnd[key] = value; }-*/; both set , work expected now.
javascript gwt
No comments:
Post a Comment