wave.getState() 返回 null
当尝试在我的 Google Wave 小工具中调用 wave.getState() 时,我返回 null(无状态对象)。如何初始化 Wave 状态对象?我在 Wave Sandbox 工作。
我的 ModulePrefs 包含以下内容:
<Require feature="wave" />
<Require feature="rpc"/>
在搜索修复程序时,我从一些谷歌小组帖子中获得了“rpc”功能,但它似乎没有任何帮助。
该小工具包含一个 jQuery 插件,它定义了我使用的类(未显示),将事件处理程序附加到在编辑模式下显示的链接,并使用 google wave 小工具初始值设定项设置回调方法:
$.fn.extend({
$.gork.InitPass.newButtonClick = function newButtonClick() {
var jer = new $.gork.InitPass.Player('Jeremias', 12, 2);
var delta = {};
delta[jer.name] = jer.serialize();
wave.getState().submitDelta(delta);
};
$.gork.InitPass.modeCallback = function modeCallback() {
var state = wave.getState();
var mode = wave.getMode();
$.gork.InitPass.getContainer().ipCombatState(state, (mode == wave.Mode.EDIT));
};
$.gork.InitPass.stateCallback = function stateCallback() {
$.gork.InitPass.getContainer().ipCombatState(
wave.getState(), (wave.getMode() == wave.Mode.EDIT));
alert('state');
};
$.gork.InitPass.init = function init() {
if (wave && wave.isInWaveContainer()) {
var mode = wave.getMode();
$('.gork-ip-container').ipCombatState(null, (mode == wave.Mode.EDIT));
wave.setModeCallback($.gork.InitPass.modeCallback);
wave.setStateCallback($.gork.InitPass.stateCallback);
}
};
})(jQuery);
gadgets.util.registerOnLoadHandler($.gork.InitPass.init);
$(function ready() {
$.gork.InitPass.getContainer().find('.gork-ip-edit .addSection a.newButton').click(
$.gork.InitPass.newButtonClick);
});
所以有两个主要的这里的功能:
- 当模式改变时,调用 ipCombatState(...)。当用户将小工具置于编辑模式 (CTRL+E) 时,这会通过隐藏视图 DIV 并显示编辑 DIV 来更改小工具的视觉外观。
- newButtonClick 回调(附加到编辑容器中的“a.newButton”链接)应该将 Jeremias(Nate 的 Shadowrun 角色)添加到小工具状态,以便他在编辑模式下显示为表格行。
我已经验证了初始化方法被调用,并且查看/编辑模式开关工作得很好(除了状态为空)。当我单击新按钮链接(编辑模式下底部的链接)并触发 newButtonClick 处理程序时,我收到错误,因为 wave.getState() 也返回 null。
如何初始化波状态以便我可以使用它?
我的小工具的用途是跟踪 Shadowrun 桌面游戏(第 4 版)中的战斗主动顺序。您可以在 Wave 中对其进行测试,看看到目前为止我得到了什么:
http://gorkwobble .herobo.com/wave/init-pass.xml
实际的 javascript 代码外部化为:
http://gorkwobble.herobo.com/wave/init-pass.js
PS 如果任何 Shadowrun 玩家读过这篇文章,并且想在我让小工具工作时听到它,请发表评论并我会向你招手。
When trying to call wave.getState() in my Google Wave gadget, I get back null (no state object). How can I initialize the Wave state object? I am working in the Wave Sandbox.
My ModulePrefs contains the following:
<Require feature="wave" />
<Require feature="rpc"/>
I got the "rpc" feature from some google groups post when searching for a fix, but it doesn't seem to be any help.
The gadget contains a jQuery plugin, which defines the classes I use (not shown), attaches an event handler to the link that shows up in edit mode, and sets up the callback methods with the google wave gadget initializer:
$.fn.extend({
$.gork.InitPass.newButtonClick = function newButtonClick() {
var jer = new $.gork.InitPass.Player('Jeremias', 12, 2);
var delta = {};
delta[jer.name] = jer.serialize();
wave.getState().submitDelta(delta);
};
$.gork.InitPass.modeCallback = function modeCallback() {
var state = wave.getState();
var mode = wave.getMode();
$.gork.InitPass.getContainer().ipCombatState(state, (mode == wave.Mode.EDIT));
};
$.gork.InitPass.stateCallback = function stateCallback() {
$.gork.InitPass.getContainer().ipCombatState(
wave.getState(), (wave.getMode() == wave.Mode.EDIT));
alert('state');
};
$.gork.InitPass.init = function init() {
if (wave && wave.isInWaveContainer()) {
var mode = wave.getMode();
$('.gork-ip-container').ipCombatState(null, (mode == wave.Mode.EDIT));
wave.setModeCallback($.gork.InitPass.modeCallback);
wave.setStateCallback($.gork.InitPass.stateCallback);
}
};
})(jQuery);
gadgets.util.registerOnLoadHandler($.gork.InitPass.init);
$(function ready() {
$.gork.InitPass.getContainer().find('.gork-ip-edit .addSection a.newButton').click(
$.gork.InitPass.newButtonClick);
});
So there are two main pieces of functionality here:
- When the mode changes, ipCombatState(...) is called. This changes the visual appearance of the gadget when the user puts the gadget in Edit mode (CTRL+E), by hiding the view DIV and displaying the edit DIV.
- The newButtonClick callback (which is attached to the link "a.newButton" in the edit container) is supposed to add Jeremias (Nate's Shadowrun character) to the gadget state, so that he'll be appear as a table row in edit mode.
I have verified that the initializer method is called, and the view/edit mode switch works just fine (except the state is null). When I click on the new button link (the link at the bottom in edit mode), and trigger the newButtonClick handler, I get an error because wave.getState() also returns null.
How can I initialize the wave state so that I can work with it?
The purpose of my gadget will be to keep track of combat initiative order in a Shadowrun tabletop game (4th Ed). You can test it out in Wave and see what I have so far:
http://gorkwobble.herobo.com/wave/init-pass.xml
The actual javascript code is externalized to:
http://gorkwobble.herobo.com/wave/init-pass.js
P.S. If any Shadowrun players read this, and want to hear about it when I get the gadget working, leave a comment and I'll wave you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论