Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jade mixins无法从外部文件工作_Javascript_Node.js_Pug - Fatal编程技术网

Javascript Jade mixins无法从外部文件工作

Javascript Jade mixins无法从外部文件工作,javascript,node.js,pug,Javascript,Node.js,Pug,我将jade mixin代码放在一个单独的文件中,并要求将该文件放在实际的jade文件中。但是混血儿没有被进口。只有当mixin代码放在同一个文件中时,它才起作用 错误是: TypeError: /home/rishabh/Documents/my_projects/getting_MEAN/loc8r/app_server/views/location-info.jade:13 11| .col-xs-12.col-sm-6 12| p.ra

我将jade mixin代码放在一个单独的文件中,并要求将该文件放在实际的jade文件中。但是混血儿没有被进口。只有当mixin代码放在同一个文件中时,它才起作用

错误是:

TypeError: /home/rishabh/Documents/my_projects/getting_MEAN/loc8r/app_server/views/location-info.jade:13
    11|         .col-xs-12.col-sm-6
    12|           p.rating
  > 13|             +outputRating(location.rating)
    14|           p= location.address
    15|           .panel.panel-primary
    16|             .panel-heading

jade_mixins.outputRating is not a function
    at eval (eval at exports.compile (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/jade/lib/jade.js:172:8), <anonymous>:159:28)
    at eval (eval at exports.compile (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/jade/lib/jade.js:172:8), <anonymous>:678:22)
    at res (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/jade/lib/jade.js:173:38)
    at Object.exports.render (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/jade/lib/jade.js:269:10)
    at Object.exports.renderFile (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/jade/lib/jade.js:305:18)
    at View.exports.renderFile [as engine] (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/jade/lib/jade.js:290:21)
    at View.render (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/view.js:76:8)
    at Function.app.render (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/application.js:502:10)
    at ServerResponse.res.render (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/response.js:777:7)
    at Object.module.exports.locationInfo [as handle] (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/app_server/controllers/locations.js:34:9)
    at next_layer (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/router/route.js:103:13)
    at Route.dispatch (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/router/route.js:107:5)
    at /home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/router/index.js:195:24
    at Function.proto.process_params (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/router/index.js:251:12)
    at next (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/router/index.js:189:19)
    at next (/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/node_modules/express/lib/router/index.js:166:38)
TypeError:/home/rishabh/Documents/my_projects/getting_MEAN/loc8r/app_server/views/location info.jade:13
11 | col-xs-12.col-sm-6
12 | p.评级
>13 |+输出(位置、额定值)
14 | p=位置。地址
15 |面板。面板-主
16 |面板标题
jade_mixins.outputring不是一个函数
在eval(eval at exports.compile(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/jade/lib/jade.js:172:8),:159:28)
在eval(eval at exports.compile(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/jade/lib/jade.js:172:8),:678:22)
在res(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/jade/lib/jade.js:173:38)
在Object.exports.render(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/jade/lib/jade.js:269:10)
在Object.exports.renderFile(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/jade/lib/jade.js:305:18)
在View.exports.renderFile[as engine](/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/jade/lib/jade.js:290:21)
在View.render(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/express/lib/View.js:76:8)
在Function.app.render(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/express/lib/application.js:502:10)
在ServerResponse.res.render(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/express/lib/response.js:777:7)
在Object.module.exports.locationInfo[作为句柄](/home/rishabh/Documents/my_projects/get_MEAN/loc8r/app_server/controllers/locations.js:34:9)
在下一层(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/express/lib/router/route.js:103:13)
在Route.dispatch(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/express/lib/router/Route.js:107:5)
at/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/express/lib/router/index.js:195:24
在Function.proto.process_参数(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/express/lib/router/index.js:251:12)
接下来(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/express/lib/router/index.js:189:19)
接下来(/home/rishabh/Documents/my_projects/get_MEAN/loc8r/node_modules/express/lib/router/index.js:166:38)
下面是我使用的mixin。我将int保存在一个单独的文件中,然后在必须使用它的jade文件中要求它

mixin outputRating(rating)
- for (var i = 1; i <= rating; i++)
span.glyphicon.glyphicon-star
- for (i = rating; i < 5; i++)
span.glyphicon.glyphicon-star-empty
mixin输出(额定值)

-对于(var i=1;i这可能应该是一个评论,而不是一个答案,但是我没有评论的特权,所以希望没有负面评论


是否可能是您将其放置在不同的目录下,而不是jade/pug文件?请指定两个文件放置在哪个文件夹目录下的文件位置。

这可能应该是一个注释,而不是一个答案,但是我没有评论的特权,所以希望没有downvoat


是否可能是您将其放置在与jade/pug文件不同的目录中?请指定两个文件放置在哪个文件夹目录下的文件位置。

我认为您的包含不正确,请重试

include ./_includes/sharedHTMLfunctions

你可以检查我的文件夹结构和包括,它为我工作

在layouts/_boostrap.pug中,我有:

include ../includes/_mixins.pug
doctype html
   html(lang="es")
       head
           ...
       body
           ...
//- bootstrap.jade
//- bootstrap mixins

//- Including Icon mixins
include ../components/icons
//- Including Alert mixins
include ../components/alerts
//- Including Tooltip mixins
include ../components/tooltips
//- Including Accordion mixins
include ../components/accordion
在includes/_mixins.pug中,我有:

include ../includes/_mixins.pug
doctype html
   html(lang="es")
       head
           ...
       body
           ...
//- bootstrap.jade
//- bootstrap mixins

//- Including Icon mixins
include ../components/icons
//- Including Alert mixins
include ../components/alerts
//- Including Tooltip mixins
include ../components/tooltips
//- Including Accordion mixins
include ../components/accordion

我认为你的内容不正确,试试看

include ./_includes/sharedHTMLfunctions

你可以检查我的文件夹结构和包括,它为我工作

在layouts/_boostrap.pug中,我有:

include ../includes/_mixins.pug
doctype html
   html(lang="es")
       head
           ...
       body
           ...
//- bootstrap.jade
//- bootstrap mixins

//- Including Icon mixins
include ../components/icons
//- Including Alert mixins
include ../components/alerts
//- Including Tooltip mixins
include ../components/tooltips
//- Including Accordion mixins
include ../components/accordion
在includes/_mixins.pug中,我有:

include ../includes/_mixins.pug
doctype html
   html(lang="es")
       head
           ...
       body
           ...
//- bootstrap.jade
//- bootstrap mixins

//- Including Icon mixins
include ../components/icons
//- Including Alert mixins
include ../components/alerts
//- Including Tooltip mixins
include ../components/tooltips
//- Including Accordion mixins
include ../components/accordion

当然,我觉得我有点晚了,你不再需要帮助了,但也许其他人会需要帮助:)

问题是您以错误的方式编写了mixin函数。在jade文件中,您不应该忘记缩进

错误版本:

mixin outputRating(rating)

-for (var i = 1; i <= rating; i++)
span.glyphicon.glyphicon-star

-for (i = rating; i < 5; i++)
span.glyphicon.glyphicon-star-empty
mixin outputRating(rating)

   -for (var i = 1; i <= rating; i++)
      span.glyphicon.glyphicon-star
    enter code here

   -for (i = rating; i < 5; i++)
      span.glyphicon.glyphicon-star-empty
mixin输出(额定值)

-对于(var i=1;i当然我觉得我有点晚了,你不再需要帮助了,但也许其他人会需要它:)

问题是您以错误的方式编写了mixin函数。在jade文件中,您不应该忘记缩进

错误版本:

mixin outputRating(rating)

-for (var i = 1; i <= rating; i++)
span.glyphicon.glyphicon-star

-for (i = rating; i < 5; i++)
span.glyphicon.glyphicon-star-empty
mixin outputRating(rating)

   -for (var i = 1; i <= rating; i++)
      span.glyphicon.glyphicon-star
    enter code here

   -for (i = rating; i < 5; i++)
      span.glyphicon.glyphicon-star-empty
mixin输出(额定值)

-对于(var i=1;i是否有帮助?包括扩展名,是否有帮助?包括扩展名,是否有帮助?是否有帮助?包括扩展名,是否有帮助文件位于适当的位置文件位于适当的位置