2016-08-15 4 views
0

Apps Script을 사용하고 으로 내용을 변환 한 결과를 표시하는 Google SheetSidebar을 만들려고합니다. Apps 스크립트를 사용하여 HtmlOutput에서 html 콘텐츠 조작

페이지 Sidebar에 대한 HTML이다 : 나는 이전에 만든

<!DOCTYPE html> 
<html> 
    <head> 
    <base target="_top"> 
    <link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css"> 
    <!-- The CSS package above applies Google styling to buttons and other elements. --> 
    <style> 
     .width-100 { 
     width: 100%; 
     height: 100% 
     } 
    </style> 
    </head> 
    <body> 
    <div class="sidebar branding-below"> 
     <form> 
     <div class="block form-group"> 
      <label for="json"><b>JSON</b></label> 
      <textarea class="width-100" id="json" name="json" rows="10"></textarea> 
     </div> 
     </form> 
    </div> 
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"> 
    </script> 
    </body> 
</html> 

JSON 원하는 이제이 방법을 사용하여 생성 된 JSONtextarea의 내용을 설정하려고 시도하고있다 :

function displayText_(text) { 
    var html = HtmlService.createHtmlOutputFromFile('Sidebar') 
    .setTitle('JSON Results'); 
    var contents = html.getContent(); 
    contents.getElementById('json').setText(text); 
    html.setContent(contents); 
    SpreadsheetApp.getUi().showSidebar(html); 
} 

다음은 답변과 함께 사용되는 JSON 문자열입니다.

var jsonString = {"someKey":"someValue","anotherKey":"anotherValue"} 

나는 htmlcontents에 연결하여 getElementById을 사용해 보았습니다. (현재의 방법). 원하는 결과를 얻을 수있는 것은 없습니다. 나는 이것이 매우 간단하다고 생각하지만, html을 조작하는 방법을 모른다. Apps Script.

나는 Apps Script 안에 전체 html 콘텐츠를 만들고 콘텐츠를 대체 할 수 있다고 확신하지만 유지 보수가 쉽지 않습니다.

더 쉬운 방법이 있나요?

답변

1

내가 알기로는, 달성하려는 것은 클라이언트 측의 서버 측에서 내용을 주입하는 것입니다. 함수 displayText_은 서버 측 함수입니다.

function displayText_(text) { 
    var htmlTemplate = HtmlService.createTemplateFromFile('Sidebar'); 
    htmlTemplate.json = text; 
    var html = htmlTemplate.evaluate().setTitle('JSON Results'); 
    SpreadsheetApp.getUi().showSidebar(html); 
} 

하고거야 클라이언트 측에서 (대신에 우리는 템플릿 파일을 사용하는 간단한 클라이언트 측 파일이있는의) :
그래서 당신은 그렇게 보일 수 있습니다 기능에 대한 서버 측 기능으로 변경 될 가능성이있는 경우에 당신은 당신이 C에서 봐 가지고해야 동적 변화를 갖고 싶어

<textarea class="width-100" id="json" name="json" rows="10"><?!=json?></textarea> 

에 대한

<textarea class="width-100" id="json" name="json" rows="10"></textarea> 

을 변경해야 lient/server 통신 프로세스 here

+0

나는 그것이 쉬울 것이라고 생각했다. 감사! – davids

관련 문제