2016-03-23 19 views
0
Burada app.js dosyasında bir komut dosyası eklemek istediğiniz

kodudur: yürütülürkennode.js'de uygulama yardımcılarını nasıl kullanabilirim?

app.helpers({ 
     renderScriptsTags: function (all) { 
     if (all != undefined) { 
      return all.map(function(script) { 
      return '<script src="/javascript/' + script + '"></script>'; 
      }).join('\n '); 
     } 
     else { 
      return ''; 
     } 
     } 
    }); 

    app.dynamicHelpers({ 
     scripts: function(req, res) { 
     return ['canvasjs.min.js']; 
     } 
    }); 

onun bana aşağıda gösterilen bir hata vermek: Hata app vermez gösteriyor gibi

app.helpers({ 
     ^
    TypeError: Object function (req, res, next) { 
     app.handle(req, res, next); 
     } has no method 'helpers' 
     at Object.<anonymous> (/var/www/html/nodeproject/helloworld/index.js:27:5) 
     at Module._compile (module.js:456:26) 
     at Object.Module._extensions..js (module.js:474:10) 
     at Module.load (module.js:356:32) 
     at Function.Module._load (module.js:312:12) 
     at Function.Module.runMain (module.js:497:10) 
     at startup (node.js:119:16) 
     at node.js:902:3 

cevap

1

helper işlev var. Uygulamanın yerine üyelik fonksiyonları size

//helper.js 
module.export = function(){ 
// Your logic here 
}; 

//usage 
var helper = require('./relative/path/to/helper'); 
var getValueFromHelper = helper(); 

gibi explicity bunları oluşturmak zorunda kalacak yardımcıları kullanmak istiyorsanız burada http://expressjs.com/en/api.html

listelenen yardımcı olur umuyoruz :)

İlgili konular