2016-07-22 2 views
0

jsreport를 사용하여 보고서를 생성하는 코드입니다. jsreport에 입력 매개 변수를 전달하여 보고서를 생성하려고합니다.jsreport에 매개 변수를 전달하여 매개 변수를 기반으로 보고서를 생성하는 방법

var express= require('express'); 
var router = express.Router(); 
var request=require('request'); 

router.get('/' ,function(req,res,next){ 
var shortid=req.query.shortid; 
var preview =req.query.preview; 

var data={ 
template:{'shortid':shortid , "recipe" : "html"}, 
options:{ 
    preview:preview 
} 
} 
var options={ 
uri:'http://localhost:5488/api/report', 
method:'post', 
json:data 
//how to pass parameter here like uri,method. 
} 
request(options).pipe(res); 
}); 
module.exports=router; 

jsreport의 스크립트에서 mysql 쿼리의 매개 변수를 전달하려고합니다.

답변

0

당신은 입력 데이터를 통해 매개 변수를 전달하거나 그런 다음 req.data.paramA에 스크립트의 매개 변수에 도달 할 수있는 옵션 속성

router.get('/' ,function(req,res,next){ 
    var shortid=req.query.shortid; 
    var preview =req.query.preview; 

    var data={ 
    template:{'shortid':shortid , "recipe" : "html"}, 
    options:{ 
     preview:preview 
    }, 
    data: { 
     paramA: 'foo' 
    } 
    } 
    var options={ 
    uri:'http://localhost:5488/api/report', 
    method:'post', 
    json:data 
    //how to pass parameter here like uri,method. 
    } 
    request(options).pipe(res); 
}); 

에 첨부 할 수 있습니다.

function beforeRender(req, res, done) { 
    var paramA = req.data.paramA 
    ... 
    done() 
} 
+0

내가 오류 (< 1.0 jsreport 사용하는 경우, 글로벌 request 객체에 도달) ..'data'이 jsreport에서 서식 파일을 실행할 때 – Abhi

+0

내가 오류 아래에 무엇입니까 정의되지 않은'오류가 발생했습니다 - 오류 렌더링 보고서 중 : evalmachine. : 28 var param = req.param.paramA; ^ 정의되지 않은 'paramA'속성을 읽을 수 없습니다. 스택 오류 : evalmachine. : 28 var param = req.param.paramA; ^' –

+0

내 샘플에 'req.data.paramA'가 있습니다. –

관련 문제