2012-04-27 65 views
0

有人能告訴我一個在kendoui上傳文件的運行示例嗎?Grails文件上傳Kendoui

正如我試圖上傳文件,並在視圖中上傳頁面,但當我點擊保存按鈕,我無法找到該文件在顯示page.I在互聯網上搜索它,然後我發現了一些server.So問題有人請告訴我如何使用服務器在我case.I'm上一個Grails項目工作

代碼,我有Used.:--

<tr class="prop"> 
<td valign="top" class="name"> 
<label>File Upload</label> 
    <input name="photos[]" id="photos" type="file" /><script>$(document).ready(function()$("#photos").kendoUpload({ 

    autoUpload:true, 
    upload: onUpload, 
    error: onError 

    }); 
     function onError(e) { 
        // Array with information about the uploaded files 
     var files = e.files; 

      if (e.operation == "upload") { 
       alert("Failed to uploaded " + files.length + " files"); 
             } 

     // Suppress the default error message 
        e.preventDefault(); 
       }, 
      function onUpload(e) { 
       var files = e.files; 
     if (e.operation == "upload") { 
      alert("Successfully uploaded " + files.length + " files"); 
        } 
      });</script> 
        </td> 
       </tr> 

我正在ading視圖文件: - 創建.gsp

<%@ page import="ten.SkeletonBill"%> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<meta name="layout" content="billing" /> 
<get var="entityName" 
value="${message(code: 'skeletonBill.label', default: 'SkeletonBill')}" /> 
<title><g:message code="default.create.label" 
args="[entityName]" /></title> 
<script src="source/kendo.all.js"></script> 
<link href="styles/kendo.common.css" rel="stylesheet" /> 
<link href="styles/kendo.default.css" rel="stylesheet" /> 

</head> 
<body> 
<content tag="menu-function"> 
<li><span class="k-link"><a href="#" 
onclick="SkeletonBillForm.submit();return false;"><i 
class="icon-plus-sign"></i> 
<g:message code="default.button.save.label" /></a></span></li> 
</content> 
<div class="body"> 
<h1> 
<g:message code="default.create.label" args="[entityName]" /> 
</h1> 
<g:if test="${flash.message}"> 
<div class="message"> 
${flash.message} 
</div> 
</g:if> 
<g:hasErrors bean="${skeletonBillInstance}"> 
<div class="alert alert-error"> 
<a class="close" data-dismiss="alert">×</a> 
<g:renderErrors bean="${skeletonBillInstance}" as="list" /> 
</div> 
</g:hasErrors> 
<g:uploadForm name="SkeletonBillForm" action="save" method="post"> 
<div class="dialog"> 
<table> 
<tbody> 

<tr class="prop"> 
<td valign="top" class="name"><label for="bones"><g:message 
code="skeletonBill.bones.label" default="Bones" /></label></td> 
<td valign="top" 
class="value ${hasErrors(bean: skeletonBillInstance, field: 'bones', 'errors')}"> 
<g:textField name="bones" 
value="${fieldValue(bean: skeletonBillInstance, field: 'bones')}" /> 
</td> 
</tr> 

<tr class="prop"> 
<td valign="top" class="name"><label for="dateOfBirth"><g:message 
code="skeletonBill.dateOfBirth.label" default="Date Of Birth" /></label> 
</td> 
<td valign="top" 
class="value ${hasErrors(bean: skeletonBillInstance, field: 'dateOfBirth', 'errors')}"> 
<g:textField name="dateOfBirth" 
value="${skeletonBillInstance?.dateOfBirth}" /> <script>$(document).ready(function() {$("#dateOfBirth").kendoDatePicker({format:"yyyy-MM-dd"})});</script> 
</td> 
</tr> 
<tr class="prop"> 
<td valign="top" class="name"> 
<label>File Upload</label> 

<input name="excelSheet" id="excelSheet" type="file" /> 

<script> 
$(document).ready(function() { 
    $("#excelSheet").kendoUpload(); 
}, 

     function onError(e) { 
// Array with information about the uploaded files 
      var files = e.files; 

      if (e.operation == "upload") { 
       alert("Failed to uploaded " + files.length + " files"); 
      } 

// Suppress the default error message 
      e.preventDefault(); 
     }, 
     function onUpload(e) { 
      var files = e.files; 
      if (e.operation == "upload") { 
       alert("Successfully uploaded " + files.length + " files"); 
      } 
     }); 
</script> 
</td> 
</tr> 

</tbody> 
</table> 
</div> 
</g:uploadForm> 
</div> 
</body> 
</html> 

也Controller.gsp

def save = { 
    def skeletonBillInstance = new SkeletonBill(params) 


    if(!skeletonBillInstance.empty){ 
     println "Name: ${skeletonBill.bones}" 
     flash.message = "${message(code: 'default.created.message', args: [message(code: 'skeletonBill.label', default: 'SkeletonBill'), skeletonBillInstance.id])}" 
     redirect(action: "show", id: skeletonBillInstance.id) 
    } 
} else { 
render(view: "create", model: [skeletonBillInstance: skeletonBillInstance]) 
} 
} 
+0

您是否定義了控制器並查看頁面? – allthenutsandbolts 2012-04-27 14:59:06

+0

你可以發佈你的視圖/ gsp頁面中的代碼嗎? – allthenutsandbolts 2012-04-27 15:13:25

+0

我的觀點頁: - create.gsp – 2012-04-30 11:40:11

回答

0

幾件事情 1)如果你想使用KendoUI,我不會使用GSP標籤。請使用正常的表單標籤來定義你的表單,如果你這樣做的話,grails可以使用原型插件。 2)我不會將腳本代碼與標籤混合。 3)如果你使用的是Grails 2.0,你可以使用KendoUI插件,你可以在http://grails.org/plugin/kendo-ui

找到更多的信息希望有所幫助。