我正试图在我的Meteor应用程序上提供一个zip文件但是我被卡住了.经过大量的谷歌搜索似乎最好的方法是与铁路由器,但我不知道如何:
Router.map ->
@route "data",
where: 'server'
path: '/data/:id'
action: ->
data = getBase64ZipData(this.params.id)
this.response.writeHead 200, { 'Content-Type': 'application/zip;base64' }
???
Run Code Online (Sandbox Code Playgroud) 在模板助手中,我从Iron.Router(iron:router)获取当前路径,如下所示:
Router.current().route.path()
Run Code Online (Sandbox Code Playgroud)
这工作正常,除非路径路径确实包含参数(例如/client/:_id/edit).在那种情况下,path()函数返回null.
当路由包含参数时,如何获取模板助手中的当前路径?
我正在使用Meteor 1.0和iron:router1.0.1
如何在两个不同的路由和模板之间传递数据?
我在前端(客户端文件夹)上有一个javascript文件,它只调用Router.go()作为我的参数之一传入帖子ID.
以下是三个主要罪魁祸首(我相信).我删除了大部分代码,以便于阅读.我可以毫无问题地更改到PostDetail页面.我还可以检索帖子ID上PostDetail从路由器页面.我的问题是,检索到的数据库条目(POLL)不会在模板上呈现.因此,即使返回数据库条目,{{Question}}也始终为空.
如果我发布更多信息,请告诉我.
FrontEnd.js
Template.PostTiles.events({
// When a choice is selected
'click .pin' : function(event, template) {
Router.go('Post', {_PostId: this.PostId});
}
});
Run Code Online (Sandbox Code Playgroud)
后detail.html
<template name="PostDetail">
<h3>{{Question}}</p>
</template>
Run Code Online (Sandbox Code Playgroud)
Shared.js
Router.map( function() {
this.route('Home', {
path: '/',
template: 'PostTiles',
data: {
// Here we can return DB data instead of attaching
// a helper method to the Template object
QuestionsList: function() {
return POLL.find().fetch();
}
}
});
this.route('Post', { …Run Code Online (Sandbox Code Playgroud) 我在使用Iron Router和Spiderable在我的Meteor.js应用程序中很好地协同工作时遇到了麻烦.如果我?_escaped_fragment_=在我的本地主机上运行时测试了一个网址,它一切正常,但是当我推送到我们的DigitalOcean生产服务器时,我在尝试同样的事情时一直收到以下错误(请查看http://hreglobal.com/?_escaped_fragment_ =):
Error: Meteor code must always run within a Fiber. Try wrapping callbacks that you pass to non-Meteor libraries with Meteor.bindEnvironment.
at Object.Meteor._nodeCodeMustBeInFiber (packages/meteor/dynamics_nodejs.js:9)
at _.extend.get (packages/meteor/dynamics_nodejs.js:21)
at RouteController.lookupOption (packages/iron:router/lib/route_controller.js:66)
at new Controller.extend.constructor (packages/iron:router/lib/route_controller.js:26)
at ctor (packages/iron:core/lib/iron_core.js:88)
at Function.Route.createController (packages/iron:router/lib/route.js:133)
at Function.Router.createController (packages/iron:router/lib/router.js:185)
at Function.Router.dispatch (packages/iron:router/lib/router_server.js:39)
at Object.router (packages/iron:router/lib/router.js:15)
at next (/opt/hre/bundle/programs/server/npm/webapp/node_modules/connect/lib/proto.js:190:15)
Run Code Online (Sandbox Code Playgroud)
一直试图找到原因几天,并开始有点绝望.欢迎任何指示!
我正在使用blaze-integrationIR 的新分支,并对现有应用程序进行了必要的更改.我在我的一个模板中有一个yield区域:
<div>
{{> yield region='signup-detail'}}
</div>
Run Code Online (Sandbox Code Playgroud)
我想在路由配置中使用设置此区域yieldTemplates.我的路线配置如下:
this.route('signUpInfo', {
path: '/sign-up',
template: 'signUp-form',
yieldTemplates: _.extend({}, mainYieldTemplates, {
'information': {to: 'signup-detail'}
})
});
mainYieldTemplates = {
'footer': { to: 'footer' },
'header': {to: 'header'}
};
Run Code Online (Sandbox Code Playgroud)
我的模板"信息"未呈现signup-detail.只有新的鲨鱼分支和IR火焰发生,使用Yield模板有什么变化?
页脚和标题模板设置正确.
编辑:模板布局
<template name="basicLayout">
{{> yield region='header'}}
<div class="container">
<div class="row">
<div class="col-md-12 col-centered padding-top-four-em">
{{> yield}}
</div>
</div>
<hr>
<footer>
{{> yield region='footer'}}
</footer>
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
编辑2:SignUp表单模板
<template name="signUp-form">
<div class="col-md-12 signup-container">
{{>signUpSideBar}}
<div class="col-md-9 signup-content gray-border-box"> …Run Code Online (Sandbox Code Playgroud) 我尝试在我的Template.rendered函数中获取返回的数据.
目前的代码是:
this.route('editCat', {
layoutTemplate : 'layoutCol2Left',
template : 'modCategoriesEdit',
path : '/mod/categories/edit/:_id',
yieldTemplates : _.extend(defaultYieldTemplates, {
'navigationBackend' : {to : 'contentLeft'}
}),
waitOn : function () {
return Meteor.subscribe('oneCat', this.params._id);
},
data : function () {
return Categories.findOne({_id : this.params._id});
}
});
Run Code Online (Sandbox Code Playgroud)
在这个块中,我等待订阅,Collection Document并将Document作为数据返回.
现在我可以在我的模板中使用返回的文档,如下所示:
<template name="modCategoriesEdit">
<h1>Edit {{name}}</h1>
</template>
Run Code Online (Sandbox Code Playgroud)
我的问题是我必须在我的渲染函数中使用返回的数据,如下所示:
Template.modCategoriesEdit.rendered = function () {
console.log(this.data);
}
Run Code Online (Sandbox Code Playgroud)
但是这会返回"null".
所以我的问题是:如何在渲染函数中访问返回的数据?
是否可以只向用户发布集合的计数?我想在主页上显示总计数,但不会将所有数据传递给用户.这是我尝试但它不起作用:
Meteor.publish('task-count', function () {
return Tasks.find().count();
});
this.route('home', {
path: '/',
waitOn: function () {
return Meteor.subscribe('task-count');
}
});
Run Code Online (Sandbox Code Playgroud)
当我尝试这个时,我得到一个无尽的加载动画.
我在本地计算机上使用Meteor 1.0.3.1,我正在使用节点v0.10.36进行部署.但是,部署机器只显示铁路由器启动画面......"铁:路由器""组织你的Meteor应用程序"......
还有其他几个关于修复这个确切问题的堆栈,包括删除标记和删除项目npm.js文件(从引导程序遗留下来).这些都不起作用.
project.js文件如下:
Router.route('/', function () {
this.render('home');
});
Router.route('/about', function () {
this.render('about');
});
Router.route('/contact', function () {
this.render('contact');
});
Router.route('/legal', function () {
this.render('legal');
});
Router.route('imitationgamereview', function () {
this.render('imitationgamereview');
});
if (Meteor.isClient) {
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}
Run Code Online (Sandbox Code Playgroud)
project.html文件如下:
<head>
<title>my sample project</title>
<link rel="shortcut icon" href="/favicon.ico?v=2" />
</head>
<template name="home">
test
</template>
Run Code Online (Sandbox Code Playgroud)
完全疯狂!WTF铁路由器?我爱上了你,那么你就这样对我这么做!
我想创建一个预加载脚本,执行许多异步函数来下载外部内容.我离这里很近,但我还没弄明白如何在我的onBeforeAction函数中推迟调用this.next().在下面的代码中,您可以看到我使用循环和setTimeout但是我以某种方式丢失了路由器的上下文,并且this.next()未定义.我相信这是因为我的preloadProject函数到了最后,路由器警告我,我忘了调用this.next(); 在我的waitToRender功能完成之前.
if (Meteor.isClient) {
IR_BeforeHooks = {
preloadProject: function() {
var itemsProcessed = 0;
_.each(items.items, function(e) {
HTTP.get(e.S3URL, {
headers: {
'Accept': '*/*'
},
responseType: 'arraybuffer' //requires aldeed:http
}, function(error, result) {
if (error) {
Session.set('error', {
'title': 'Could not download',
'message': error
});
}
if (result) {
itemsProcessed = itemsProcessed + 1;
}
}) //http get
}) //each
function waitToRender(router) {
console.log('waiting...')
var progress = (itemsProcessed / items.items.length) * 100;
if (progress < 100) {
$('.progress-bar').css('width', Math.floor(progress) + …Run Code Online (Sandbox Code Playgroud) 有没有办法data在使用IronRouter时扩展选项,并且RouteController,当我从超级控制器继承时它似乎被覆盖,子控制器不会扩展定义的data属性.我yieldTemplates在路由上遇到类似问题并使用了解决方法(下划线_extends)但在这种情况下它不起作用:
ApplicationController = RouteController.extend({
data: function(){
return {
user: Meteor.user()
}
}
});
ChildController = ApplicationController.extend({
data: function(){
return {
// I expect to inherit Meteor.User ?????
someData: {}
}
}
});
Run Code Online (Sandbox Code Playgroud)
编辑:
在使用underscore和extend继承原型函数的函数之后,我仍然无法继承route使用的定义ChildController
this.route('someRoute', {
template: 'task_template',
//tasks is not available on the template
data: function () {
var base = ChildController.data.call(this);
console.log(base);
return _.extend(base, {
tasks: Tasks.find({state: 'Open'})
});
});
Run Code Online (Sandbox Code Playgroud)