首页 > 解决方案 > 如何将表单值传递到新窗口?

问题描述

我有一个需要在新窗口中打印的表格。我可以传递表单的innerHTML,但它似乎没有得到值。这是一个示例代码:

print: function(){
var formPanel = Ext.getCmp('formPanelId');
var formValues = formPanel.getValues(); //this has data but it does not load on the new Window
var myWindow = window.open('', '', 'width=200,height=100');
myWindow.document.write('<html><head>');
myWindow.document.write('<title>' + 'Title' + '</title>');
myWindow.document.write('<link rel="Stylesheet" type="text/css" href="http://dev.sencha.com/deploy/ext-4.0.1/resources/css/ext-all.css" />');
myWindow.document.write('<script type="text/javascript" src="http://dev.sencha.com/deploy/ext-4.0.1/bootstrap.js"></script>');
myWindow.document.write('</head><body>');
myWindow.document.write(formPanel.body.dom.innerHTML);
myWindow.document.write('</body></html>');
}

如何将 formValues 传递到新窗口?我很感激对此的任何建议。谢谢!

标签: extjs

解决方案


如果您想将这些值传递给 Ext.window.Window 您可以在创建 Ext 窗口时简单地执行此操作,如下所示

print: function(){ 
 var formPanel = Ext.getCmp('formPanelId');
 var formValues = formPanel.getValues();
 var myWindow = Ext.create('YourWinodw', {formPanelValues:formValues}); // now in myWindow there is property formPanelValues that hold that value
}

如果您像上面那样使用普通的 window.document.write ,则需要立即编写如下值

myWindow.document.write('<html><head>');
myWindow.document.write('<title>' + formValues['fieldName'] + '</title>'); 

推荐阅读