我有一个表单在模式对话框中,一旦表单被提交我必须用表单数据更新边栏。如何实现?我试过在特定的时间间隔轮询表格数据。还有其他解决方法吗?谷歌脚本中的边栏和模式对话框之间的沟通
1
A
回答
1
那么这里对话框和边栏
之间的沟通的的东西是相当接近的,你在说什么的例子。这是我为了学习如何处理PropertiesService而编写的。它并不完整,但其中一些工作正常,您可以通过PropertiesService存储将信息从对话框传递到边栏。尽管如此,您可以在那里存储多少钱。我没有确切的数字,但我知道26KB太多了。
因此无论如何,一旦它运行,您可以使用其中一个发件人文本框编写消息并按发件人按钮,消息将转到PropertiesService,然后回到对话框或侧栏,通过onSuccessHandler,它将被写入对话文本框中。如果您在另一个对话框或侧栏上按刷新,那么它的对话也会更新。
我猜你可能会找到一种方法来自动执行刷新。
无论如何,这个例子涵盖了许多你可能想要覆盖的同样的理由。当然要意识到我不是Google Guru,所以不要以为我做事情的方式是最好的方式,甚至是一种好的方式。但它确实有效。
code.gs
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('My Handler Tools')
.addItem('Show MyDialog1','MyDialog1')
.addSeparator()
.addItem('Show MyDialog2','MyDialog2')
.addSeparator()
.addItem('Show SideBar3','SideBar3')
.addSeparator()
.addItem('Log Settings','logSettings')
.addItem('Delete Conversation','delConversation')
.addToUi();
};
function delConversation()
{
PropertiesService.getDocumentProperties().deleteAllProperties();
}
function savConversation(conversation)
{
PropertiesService.getDocumentProperties().setProperties(conversation);
return(conversation);
}
function getConversation()
{
var conversation = PropertiesService.getDocumentProperties().getProperties();
if(typeof(conversation.active) == 'undefined')
{
conversation = {'thread': '***** Start a new thread *****', 'active': true};
}
return conversation;
}
function MyDialog1()
{
var ui = HtmlService.createHtmlOutputFromFile('ModeLessDialog')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setWidth(420)
.setHeight(600);
SpreadsheetApp.getUi().showModelessDialog(ui,'MyDialog1');
}
function MyDialog2()
{
var msg = '<html><head><link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">\
<style>\
#my_block{border:5px solid green;padding:10px 10px 10px 0px;}\
</style></head><body><div id="my_block">\
<input type="button" value="Button1" name="Button1" id="My_Button_1" class="My_Tools" />\
<br /><div style="margin-bottom:5px;"><input type="text" value="This is text" id="My_Text_1" class="My_Tools" name="Text1" />\
<br /><input type="button" value="Button2" name="Button2" id="My_Button_2" class="My_Tools" />\
<br /><input type="text" value="This is text" id="My_Text_2" class="My_Tools" name="Text2" />\
<br /><input type="button" value="Exit" onClick="google.script.host.close();" />\
</div></body></html>';
var title = 'MyDialog2';
dispStatus(title,msg);
}
function SideBar3()
{
var ui = HtmlService.createHtmlOutputFromFile('ModeLessDialog').setTitle('Handler Communications');
SpreadsheetApp.getUi().showSidebar(ui);
}
function logSettings(show)
{
var show = typeof(show) !== 'undefined' ? show : true;
var settings = PropertiesService.getDocumentProperties().getProperties();
var html = '<html><head><link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">\
<style>.branding-below{bottom:54px;top:0;}\
.branding-text{left:7px;position:relative;top:3px;}\
.logo{vertical-align:middle;}\
.width-100{width:100%;box-sizing:border-box;-webkit-box-sizing:border-box;?-moz-box-sizing:border-box;}\
label{font-weight:bold;}\
#creator-options,#respondent-options{background-color:#eee;border-color:#eee;border-width:5px;border-style:solid;display:none;}\
#creator-email,#respondent-email,#button-bar,#submit-subject{margin-bottom:10px;}\
#response-step{display:inline;}</style></head>\
<body><div class="sidebar branding-below"><form><h3>Conversation Settings</h3><div class="block" style="border:2px solid black;padding:10px 5px 10px 5px;">';
Logger.clear();
for(var key in settings)
{
html += '<br />' + key + ' = ' + settings[key];
Logger.log(key + ' = ' + settings[key]);
}
html += '<br /><div class="block blockgroup"><input type="button" class="action" value="Exit" onclick="google.script.host.close();" /></div>';
html += '</div></div></form></body></html>';
if(show)dispStatus('Document Properties',html,400,400);
}
function dispStatus(title,html,width,height)
{
// Display a modeless dialog box with custom HtmlService content.
var title = typeof(title) !== 'undefined' ? title : 'No Title Provided';
var width = typeof(width) !== 'undefined' ? width : 250;
var height = typeof(height) !== 'undefined' ? height : 300;
var html = typeof(html) !== 'undefined' ? html : '<p>No html provided.</p>';
var htmlOutput = HtmlService
.createHtmlOutput(html)
.setWidth(width)
.setHeight(height);
SpreadsheetApp.getUi().showModelessDialog(htmlOutput, title);
}
ModeLessDialog.html
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
<style>
#my_block{border:2px solid black;background-color:rgba(0,150,255,0.2);padding:10px 10px 10px 10px;}
#conv_block{border: 1px solid black;padding:10px 10px 10px 10px;}
.bttn_block{padding:5px 0px 10px 0px;}
.sndr_block {border:1px solid rgba(0,150,0,0.5);background-color:rgba(150,150,0,0.2);margin-bottom:2px;}
</style>
</head>
<body>
<form>
<div id="my_block" class="block form-group">
<div class="sndr_block">
<strong>Sender 1</strong>
<br /><input type="text" size="30"value="" id="sender1msg" class="action" />
<br /><div class="bttn_block"><input type="button" value="Send" name="Sender1" id="sender1" class="action" /></div>
</div>
<div class="sndr_block">
<strong>Sender 2</strong>
<br /><input type="text" size="30" value="" id="sender2msg" class="action" />
<br /><div class="bttn_block"><input type="button" value="Send" name="Sender2" id="sender2" class="action" /></div>
</div>
<div id="conv_block">
<strong>Conversation</strong>
<br /><textarea id="conversation" rows="10" cols="35"></textarea>
<br /><input type="button" value="Save" name="Save" id="save-msg" class="action" />
<input type="button" value="Delete" name="Delete" id="del-msg" class="action" />
<input type="button" class="action" id="disp-log-setting" value="Settings" onClick="google.script.run.logSettings();" />
<input type="button" value="Refresh" class="action" id="refresh" />
</div>
<div id="btn-bar">
<br /><input type="button" value="Exit" onClick="google.script.host.close();" class="green" />
</div>
</div>
</form>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
</script>
<script>
$(function() {
$('#sender1').click(sendMessage1);
$('#sender2').click(sendMessage2);
$('#del-msg').click(deleteConversation);
$('#save-msg').click(saveConversation);
$('#refresh').click(refreshConversation);
google.script.run
.withSuccessHandler(updateConversation)
.withFailureHandler(showStatus)
.getConversation();
});
function sendMessage1()
{
var message = $('#conversation').val() + '\nSender1:\n' + $('#sender1msg').val();
var newconversation = {'thread': message, 'active': true};
$('#sender1msg').val('');
$('#conversation').css("background-color", "#ffe866");
google.script.run
.withSuccessHandler(updateConversation)
.withFailureHandler(showStatus)
.savConversation(newconversation);
}
function sendMessage2()
{
var message = $('#conversation').val() + '\nSender2:\n' + $('#sender2msg').val();
var newconversation = {'thread': message, 'active': true};
$('#sender2msg').val('');
$('#conversation').css("background-color", "#ffe866");
google.script.run
.withSuccessHandler(updateConversation)
.withFailureHandler(showStatus)
.savConversation(newconversation);
}
function deleteConversation()
{
var conversation = {'thread': '***** Start a new thread *****', 'active': true};
$('#conversation').css("background-color", "#ffe866");
google.script.run
.withSuccessHandler(updateConversation)
.withFailureHandler(showStatus)
.savConversation(conversation);
}
function saveConversation()
{
var message = $('#conversation').val();
var newconversation = {'thread': message, 'active': true};
$('#conversation').css("background-color", "#ffe866");
google.script.run
.withSuccessHandler(updateConversation)
.withFailureHandler(showStatus)
.savConversation(newconversation);
}
function updateConversation(conversation)
{
$('#conversation').val(conversation.thread);
$('#conversation').css("background-color", "white");
}
function refreshConversation()
{
$('#conversation').css("background-color", "#ffe866");
google.script.run
.withSuccessHandler(updateConversation)
.withFailureHandler(showStatus)
.getConversation();
}
function showStatus()
{
dispStatus('showStatus','This is status');
$('#conversation').css("background-color", "#ffb3b3");
}
console.log('ModeLessDialogJavaScript');
</script>
</body>
</html>
相关问题
- 1. 会话之间的沟通
- 2. 谷歌地图模式对话框(JQuery)
- 3. 谷歌应用程序引擎服务之间的沟通
- 4. 边栏宽度不使用谷歌应用程式脚本
- 5. 谷歌应用脚本边栏不显示Chrome中的内容
- 6. 谷歌日历的谷歌脚本日期和时间的格式
- 7. JFrames之间的沟通
- 8. 班级之间的沟通
- 9. 视图之间的沟通
- 10. 谷歌地图和jQuery UI对话框
- 11. 片段和活动之间的沟通
- 12. AppsScript和Wordpress之间的沟通
- 13. PHP和Javascript之间的沟通
- 14. 服务和intentservice之间的沟通
- 15. 当模式对话关闭时,如何加载谷歌插件的侧边栏中的特定部分?
- 16. 窗口和模态对话框之间的会话传输
- 17. jQueryUI模式对话框中的脚本只能工作一次
- 18. 通过MFC对话框中的对话框边距绘图
- 19. 模态对话框中的谷歌Chrome扩展
- 20. 跨域的iFrame和父页之间可能的沟通方式
- 21. 通过另一个模式对话框的JQueryUI模式对话框
- 22. JavaScript和模式对话框
- 23. iPhone和Macbook笔记本电脑之间的沟通
- 24. 从SimpleModal模式对话框中提交与jQuery在Firefox 3和歌剧在SimpleModal模式对话框
- 25. 谷歌应用程序脚本的正则表达式电话
- 26. 谷歌脚本之间的共享代码
- 27. 谷歌应用程序脚本之间的部件宽度
- 28. 输入和模态对话框之间的区别
- 29. 模型对话框和呼叫者功能之间的链接
- 30. 对谷歌的PHP脚本映射
你的代码添加到您的Q. – xlm
请看一看在以下链接答案:[栈溢出答案](http://stackoverflow.com/a/41265164/2946873) –