Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.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
Ember.js 如何将预编译模板显示到特定视图_Ember.js_Routes_Handlebars.js_Router - Fatal编程技术网

Ember.js 如何将预编译模板显示到特定视图

Ember.js 如何将预编译模板显示到特定视图,ember.js,routes,handlebars.js,router,Ember.js,Routes,Handlebars.js,Router,有人能帮助我如何将生成的预编译车把显示到特定视图中吗 var aboutData=[{…},…] App.Router.map(function() { this.resource('about); }); // When navigating to url: www.../#/about // This whole thing generates a view appended to the body // I want the generated handlebars to be

有人能帮助我如何将生成的预编译车把显示到特定视图中吗

var aboutData=[{…},…]

App.Router.map(function() {
   this.resource('about);
});


// When navigating to url: www.../#/about
// This whole thing generates a view appended to the body
// I want the generated handlebars to be appended somewhere specific
App.aboutDataRoute = Ember.Route.extend({
  model: function() {
     return aboutData;
  }
});
有几件事:

:您的路由应称为
About
,因为您在
路由器中创建了
About
资源。路由名称将与如下结构匹配:

App.Router.map(function() {
    this.resource('about', function() {
        this.route('data');
    });
});
在本例中,您将有一些隐含的路由和您将以声明方式创建的路由(更多关于它的信息,尽管第二个链接很旧)。但基本上,在这个路由器定义中,名称
aboutData Route
将起作用,因为按照惯例,这个名称将父(About)和子(Data)路由的名称加上后缀
Route
。对于您定义的路由,一旦转到
~/#/about
,Ember将忽略您创建的路由类,并动态生成该路由的默认实现(您可以在中看到),因为这与约定不匹配

:通常,您应该使用
PascalCase
来命名大多数事物,但您的名称是
camelCase
。尝试阅读更多有关命名约定的内容


至于您的问题,您可以在不同的元素中呈现应用程序,没有问题。只是在中,
主体
被设置为默认值。您可以这样更改它:

App = Em.Application.create({
    rootElement: '#selector'
});
其中,
#选择器
在本例中可以是DOM中的任何元素


请记住,应用程序视图是应该在“this”或“that”DOM元素中呈现的视图。所有其他视图都是应用程序视图的某种类型的子视图(直接或间接),因此它们将在
{{outlet}
中呈现,因此您应该在
应用程序
具体类中进行呈现。

我明白了。。。我最近在练习余烬。我想这澄清了我的大部分问题。谢谢无论如何,在使用Ember.View时,是否也可以指定在何处插入DOM?例如,App.AboutView=Ember.View.extend({template:Ember.template.about//这已经是一个预编译的手柄});如果遵循约定,则不必指定视图的模板,因为它将找到匹配的名称并自动使用该模板。顺便说一句,你的模板总是经过编译的,问题是你可以将它们作为html文档的一部分预先编译或放入
script
标记中,即使是这样,它们仍然会在你的应用程序初始化期间被编译。因此,如果您仍然需要为视图手动指定模板,请遵循并使用类似
templateName:“其他名称”