如何连接一个骨干视图流星车把模板? [英] How to wire a Backbone View to a meteor handlebars template?

查看:87
本文介绍了如何连接一个骨干视图流星车把模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来像Backbone.view,流星和车把有重叠的功能,当涉及到操纵DOM的一部分。我看着它想利用骨干待办事项应用程序,但在现实中,他们只用路由器。

Looks like Backbone.view, meteor and handlebars have overlap functionality when it comes to manipulating a section of the DOM. I looked at the ToDo app which is suppose to use Backbone, but in reality, they only use the Router.

主干意见还应对模板......但他们的声音从流星模板,以便不同。此外,它看起来像两个骨架放;流星可以更新模型更新UI。

Backbone views also deal with templates... but they sound so different from meteor templates. Besides, it looks like both backbone & meteor can update the ui on a model update.

好吧,我迷路了!?谁做什么?

ok, I am lost!? Who does what?

是一个流星应用骨干真的有用吗?可以骨干和放大器;车把共存?
如果他们能在流星的背景下,如何把一个骨干视图到车把模板?

Is Backbone really useful for a Meteor App? Can Backbone & Handle bars coexist? and if they can, in the Meteor context, how to wire a Backbone view to a handlebars template?

编辑:找到了待办事项骨干的例子。这似乎也印证了,你可以去任何一种:

found the todo-backbone example. it seems to confirm that you can go either:


  • 流星+骨干+下划线模板

  • 或...流星+车把

流星+骨干+车把似乎不是一种可行的选择...

meteor+backbone+handlebars doesn't seem like a viable option...

感谢您

推荐答案

这是很容易的,不超过使用下划线模板更多的工作。下面是一个例子.html文件:

It's very easy and no more work than using the Underscore template. Here's an example .html file:

<template name="user_list">
<ul>
  {{#each users}}
  <li>{{name}}</li>
  {{/each}}
</ul>
</template>

这是一个例子.js文件:

And here's an example .js file:

Users = new Meteor.collection("users");

if (Meteor.is_client) {
  Template.user_list.users = function() {
    return Users.find();
  }

  window.UserView = Backbone.View.extend({
    initialize: function() {
      _.bindAll(this, 'render');
    },
    template: function() {
      Meteor.ui.render(function() {
        return Template.user_list();
      });
    },
    render: function() {
      $(el).empty().append(this.template());
    }
  });
}

您就可以使用路由器或其他视图来管理,当你想要显示的UserView就像你在任何其他应用程序Backbone.js的

You can then use a Router or another View to manage when you want to display the UserView just like you would in any other Backbone.js app.

的关键是使用Meteor.ui.render或其它Meteor.ui方法呈现HTML,以便它的反应性

The key is to use the Meteor.ui.render or other Meteor.ui method to render the HTML so that it's reactive.

这篇关于如何连接一个骨干视图流星车把模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆