Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.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
Meteor:仅将.html从特定子目录加载到页面中_Meteor - Fatal编程技术网

Meteor:仅将.html从特定子目录加载到页面中

Meteor:仅将.html从特定子目录加载到页面中,meteor,Meteor,我正在尝试使用Meteor、Meteor Router和Bootstrap创建一个简单的快速原型项目 这是目录结构 meteor-prototypes/ | |--- .meteor/ |--- prototypes/ | | | |--- example/ | | | |--- example.coffee | |--- example.css | |--- example-index.html | |

我正在尝试使用Meteor、Meteor Router和Bootstrap创建一个简单的快速原型项目

这是目录结构

meteor-prototypes/
|
|--- .meteor/
|--- prototypes/
|    |
|    |--- example/
|         |
|         |--- example.coffee
|         |--- example.css
|         |--- example-index.html
|         |--- example-more.html
|
|--- prototypes.coffee
|--- index.html
|--- smart.json
|--- smart.lock
if (Meteor.isClient)

  Meteor.Router.add
    '': 'home'

    '/:prototype': (params) ->
      return params

    '/:prototype/:page': (params) ->
      return params[1]

if (Meteor.isServer)
  Meteor.startup ->
    # code to run on server at startup
if Meteor.isClient
  Template.example.greeting = ->
    return "Welcome to prototypes."

  Template.example.rendered = ->
    # This function will fire when this specific template gets rendered,
    # Great place to fire jQuery plugins, or anything else that needs
    # to happen when the DOM is ready.

  Template.example.events
    'click input' : ->
      # template data, if any, is available in 'this'
      alert 'Button clicked!'
example
文件夹表示单个原型,可在(例如)
http://localhost:3000/prototypes/example/
。理想情况下,只需使用新名称(例如新示例)复制
example/
,然后访问
http://localhost:3000/prototypes/new-示例/

问题是Meteor默认情况下会在整个项目目录中搜索HTML文件并将其全部加载。我需要做的是根据URL(通过Meteor Router)检查我们正在查看的原型,并只加载该文件夹中的.html文件(例如,
example/

有没有办法告诉Meteor只加载特定子目录中的.html文件?还是其他方法来实现这一点?

对于那些好奇的人,或者如果有帮助的话,下面是上面目录结构中提到的每个文件所包含的内容:

index.html

<head>
  <title>desktime-prototypes</title>
</head>

<body>
  {{ renderPage }}
</body>

<template name="home">
    <h1>We have the following prototypes available:</h1>

    <ul>
        <li><a href="/example/">Example</a></li>
    </ul>
</template>
<template name="example">
    <h1>Welcome to the example prototype!</h1>

    {{> example-more }}
</template>
/prototype/example.coffee

meteor-prototypes/
|
|--- .meteor/
|--- prototypes/
|    |
|    |--- example/
|         |
|         |--- example.coffee
|         |--- example.css
|         |--- example-index.html
|         |--- example-more.html
|
|--- prototypes.coffee
|--- index.html
|--- smart.json
|--- smart.lock
if (Meteor.isClient)

  Meteor.Router.add
    '': 'home'

    '/:prototype': (params) ->
      return params

    '/:prototype/:page': (params) ->
      return params[1]

if (Meteor.isServer)
  Meteor.startup ->
    # code to run on server at startup
if Meteor.isClient
  Template.example.greeting = ->
    return "Welcome to prototypes."

  Template.example.rendered = ->
    # This function will fire when this specific template gets rendered,
    # Great place to fire jQuery plugins, or anything else that needs
    # to happen when the DOM is ready.

  Template.example.events
    'click input' : ->
      # template data, if any, is available in 'this'
      alert 'Button clicked!'
原型/example/example index.html

<head>
  <title>desktime-prototypes</title>
</head>

<body>
  {{ renderPage }}
</body>

<template name="home">
    <h1>We have the following prototypes available:</h1>

    <ul>
        <li><a href="/example/">Example</a></li>
    </ul>
</template>
<template name="example">
    <h1>Welcome to the example prototype!</h1>

    {{> example-more }}
</template>

欢迎使用示例原型!
{{>示例更多}

好问题……两件事:

(1)
流星路由器目前缺少所需的服务器端渲染()

(2)HTML文件名与路由系统完全无关。它们所在的文件夹在加载顺序上很重要,但名称与您期望的路由方式不匹配

为了实现您想要的功能,您可以(1)使用应用程序中的链接进行路由,但不要更改地址栏中的URL,并希望它能正常工作;(2)更改/prototype文件夹中各种html文件的模板名称,以匹配您要演示的原型。以下是一个例子:

HTML:

原型1 HTML:

<template name="prototype1">
    <h1>Prototype 1</h1>
</template>

原型1
Prototype 2 HTML:

<template name="prototype2">
    <h1>Prototype 2</h1>
</template>

原型2

好问题……两件事:

(1)
流星路由器目前缺少所需的服务器端渲染()

(2)HTML文件名与路由系统完全无关。它们所在的文件夹在加载顺序上很重要,但名称与您期望的路由方式不匹配

为了实现您想要的功能,您可以(1)使用应用程序中的链接进行路由,但不要更改地址栏中的URL,并希望它能正常工作;(2)更改/prototype文件夹中各种html文件的模板名称,以匹配您要演示的原型。以下是一个例子:

HTML:

原型1 HTML:

<template name="prototype1">
    <h1>Prototype 1</h1>
</template>

原型1
Prototype 2 HTML:

<template name="prototype2">
    <h1>Prototype 2</h1>
</template>

原型2

在一个Meteor项目中需要多个原型有什么原因吗?他们共享代码吗?如果不是,为什么不每个原型使用一个流星项目呢?然后你可以自己创建一个命令行util

meteor_proto example1
meteor_proto example2
这将创建Meteor项目,但只是用您想要的文件预先填充它们(您可以创建理想的原型项目并将其放在某个地方,然后在执行
Meteor create
命令或其他操作后,让您的命令行复制该文件夹的内容)


事实上,这对于Meteor来说是一个很好的默认特性。

您希望在一个Meteor项目中包含多个原型有什么原因吗?他们共享代码吗?如果不是,为什么不每个原型使用一个流星项目呢?然后你可以自己创建一个命令行util

meteor_proto example1
meteor_proto example2
这将创建Meteor项目,但只是用您想要的文件预先填充它们(您可以创建理想的原型项目并将其放在某个地方,然后在执行
Meteor create
命令或其他操作后,让您的命令行复制该文件夹的内容)


<>这是流星在默认情况下的一个很好的特性。

拉胡尔:谢谢你的评论,我确实考虑过你所描述的每一个原型都有一个项目。我没有这么做有两个主要原因:1)枯燥,我不想维护十几个项目2)原型通常是同一个应用程序设计过程的一部分,如果他们能在需要时相互沟通/链接就好了。另外,我已经考虑了很久,流星需要从模板创建新项目的便捷方式(例如,流星创建我的项目-T我的模板)RuHul:谢谢你的评论,我确实考虑过每一个原型都有一个项目,就像你描述的那样。我没有这么做有两个主要原因:1)枯燥,我不想维护十几个项目2)原型通常是同一个应用程序设计过程的一部分,如果他们能在需要时相互沟通/链接就好了。另外,我一直认为Meteor需要一种从模板创建新项目的便捷方式(例如Meteor创建我的项目-t我的模板)是的,这是有意义的。我不明白为什么我不应该期望URL映射到路由?正如你所描述的,难道不能正确映射到原型模板吗?@cmal:如果meteor router;i、 例如,spark引擎在服务器上运行。我知道他们的应用程序中有路由包。当您运行此应用程序并从应用程序本身中单击Prototype1链接时,您将看到是的URL。但是你不能在地址栏中输入,直到服务器端渲染被支持,你才能看到同样的东西。是的,这是有意义的。我不明白为什么我不应该期望URL映射到路由?正如您所描述的,无法正确映射到原型模板