小编was*_*dev的帖子

如何使用express.js配置动态路由

我有一个如下所示的route.js:

module.exports = function(app) {

  app.get('/tip', function(req, res) {
    res.render("tip");
  });

  app.get('/article', function(req, res) {
   res.render("article");
  });

  app.get('/article1', function(req, res) {
   res.render("article1");
  });

  app.get('/article2', function(req, res) {
   res.render("article2");
  });

  app.get('/article3', function(req, res) {
   res.render("article3");
  });

  app.get('/modules/:name', function(req, res) {
    var name = req.params.name;
    res.render('modules/' + name);
  });

  app.get('/modules/esaver/:name', function(req, res) {
    var name = req.params.name;
    res.render('modules/esaver/' + name);
  });

};
Run Code Online (Sandbox Code Playgroud)

考虑到我有超过200条不同的路线要创造,我最终会得到像'article1','article2'等东西

我的app.js就像:

var express = require('express')
  ,http = require('http')
  ,fs = require('fs')
  ,path = require('path');

var app = express();

html_templates …
Run Code Online (Sandbox Code Playgroud)

javascript node.js express

38
推荐指数
4
解决办法
5万
查看次数

如何从循环动态创建多个UL LI - javascript/jquery/magento

我试图读取由magento-spConfig创建的全局变量,并基于它创建多个无序列表.我的Javascript代码:

   if(typeof spConfig !='undefined'){
    if(typeof spConfig[0] == 'undefined' ) {
        spConfig[0] = spConfig;
    }
    var index  = 0 , count = spConfig.length?spConfig.length:1;
    for( var index  = 0 ; index<count;index++) {
        if(typeof spConfig != 'undefined' && typeof spConfig[index].config != 'undefined' && typeof spConfig[index].config.attributes != 'undefined') {
            for(var attributeID in spConfig[index].config.attributes) {

               //alert(attributeID) gives (the number of ul's i want)
                var ul = jQuery('<ul id="clone'+attributeID+'"></ul>');

                for(var optionID in spConfig[index].config.attributes[attributeID].options) {
                    var option = spConfig[index].config.attributes[attributeID].options[optionID];
                    if(typeof option == 'object') {

                       // alert(option.label); gives …
Run Code Online (Sandbox Code Playgroud)

javascript jquery

0
推荐指数
1
解决办法
1082
查看次数

标签 统计

javascript ×2

express ×1

jquery ×1

node.js ×1