Backbone.js的父母与子女的意见 [英] Backbone.js parent vs. child views

查看:133
本文介绍了Backbone.js的父母与子女的意见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Backbone.js的为前端开发,有没有渲染渲染其各自的父视图前一个子视图一种可靠的方法?是否有这样的格局?我能够使孩子的意见,但我必须要小心,首先总是渲染父。有没有一种模式为父母之前妥善渲染的孩子?

Using Backbone.js for front-end development, is there a reliable way to render a child view before rendering its respective parent view? Is there a pattern for this? I am able to render child views but I have to be careful to always render the parent first. Is there a pattern for safely rendering children before parents?

推荐答案

还有就是要做到这一点,使用jQuery的一种方式。 jQuery有一个查找()函数。 https://api.jquery.com/find/

There is one way to do this, using jQuery. jQuery has a find() function. https://api.jquery.com/find/

说我有一个创建并写入到这是一个 DIV )一Backbone.View实例C $ C>默认元素。在code以下是我的看法的渲染函数中:

say I have a Backbone.View instance that creates and writes to its self-defined element (el) which is a div element by default. The code below is inside the render function of my view:

              var self = this;

              var ret = EJS.render($template, {});  //get the template html

              self.$el.html(ret);  //put the html string into self.$el (still not in the DOM though!!)

              //Facebook's React.js lib
              React.render(
                  <TimerExample start={Date.now()} />,
                   $(self.el).find('#react-timer-example-div-id')[0]
               );


              React.render(
                  <MenuExample items={ ['Home', 'Services', 'About', 'Contact us'] } />,
                  $(self.el).find('#react-menu-example-div-id')[0]
               );


             //using the two-way data binding lib "Rivets"
             Rivets.bind( $(self.el).find('#some-id')[0], {obj: exampleObj})

以上的作品,我会说这是一个很好的解决方案,以使子视图父视图,无父视图首先在DOM之中。这一招,正如我所说,是用 $(this.el).find('#XYZ'); 。如果有更好的办法,我很想听到它,但这似乎工作得很好。

The above works, and I would say it's a great solution to render child views to a parent view, without the parent view first being in the DOM. The trick, as I said, is to use $(this.el).find('#xyz');. If there is a better way, I'd love to hear it, but this seems to work quite well.

我由$模板psented上述复试$ P $模板,看起来是这样的:

My template for the above represented by $template, looks like this:

<div>
    <div id="react-timer-example-div-id">timer example goes here</div>
    <div id="react-menu-example-div-id">menu example goes here</div>
    <div id="some-id">blah blah</div>
</div>

这篇关于Backbone.js的父母与子女的意见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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