Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.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 在主干中的视图中渲染子视图_Javascript_Jquery_Backbone.js_Requirejs - Fatal编程技术网

Javascript 在主干中的视图中渲染子视图

Javascript 在主干中的视图中渲染子视图,javascript,jquery,backbone.js,requirejs,Javascript,Jquery,Backbone.js,Requirejs,嗨,我正在努力理解我将如何做以下事情 我有一个渲染的主干视图,然后我想向该视图中的dom元素添加另一个视图 以下是我的代码: define([ 'jquery', 'underscore', 'backbone', 'views/common/parent', 'text!templates/currentAccounts.html', 'text!templates/guidesTools.html' ], function($, _, Backbone, Parent

嗨,我正在努力理解我将如何做以下事情

我有一个渲染的主干视图,然后我想向该视图中的dom元素添加另一个视图

以下是我的代码:

define([
  'jquery',
  'underscore',
  'backbone',
  'views/common/parent',
  'text!templates/currentAccounts.html',
  'text!templates/guidesTools.html'
], function($, _, Backbone, ParentView, mainTemplate, subTemplate){

var accountsView = ParentView.extend({
    render : function() {
        this.$el.html(mainTemplate);
    }
});

return new accountsView;
}))


现在我需要将子模板(guidesTolls.html)附加到主模板中的dom元素。最好的方法是什么?

请尝试从

本部分包括两个模型和三个视图

  • 模型/集合
    • Todo模型
    • 托多利斯特收藏
  • 观点
    • 待办事项视图
    • 托多利斯特观点
    • 应用程序视图
应用程序视图基于TodoList视图渲染视图,该视图渲染每个Todo对象的Todo视图

你的情况比那简单。具体地说,您可以执行类似的操作来创建包含子视图的视图

<div id="main">
</div>
<script type="text/template" id="main-template">
    <h3>main view</h3>
    <ul>
      <li><%= account.id %></li>
      <li><%= account.name %></li>
    <ul>
    <div id="guide-tools"></div>
</script>

注意:我不知道如何从html文件中获取文本,特别是如果您使用的是服务器端脚本。

非常感谢,我错过了主干上的“要做”部分。我会试试你的建议:)再次谢谢。
var accountsView = ParentView.extend({
    el: $("#main")
    render : function() {
        var template = _.template($("#main-template").html());
        var guideTemplate = "Guide Tool Text";
        this.$el.html(template(this.model.toJSON()));
        this.$("#guide-tools").html(guideTemplate);  // will insert the guide page to the #main div
    }
})