gpt4 book ai didi

javascript - Ember 模板链接

转载 作者:行者123 更新时间:2023-11-28 01:55:00 25 4
gpt4 key购买 nike

我有这个 HTML/Handlebars 代码,我想要的是渲染“outlet fav”id 为“fav”的模板及其相应的带有预期“index”的导出/模板链。有点像显示不同的 Ember URL 作为索引的一部分。原生是否可能(不补充 iframe,我认为这是一个坏主意)?这会被认为是一个好的做法吗(我知道使用 View 可能会有所帮助,但只是想知道走这条路是否可以)?

<script type="text/x-handlebars" id="application">
Here we have our application
{{outlet}}
</script>

<script type="text/x-handlebars" id="index">
Application's First Child
{{outlet}}
</script>

<script type="text/x-handlebars" id="index/index">
Your Favourites
{{outlet fav}}
</script>

<script type="text/x-handlebars" id="fav">
{{#link-to 'fav'}}All{{/link-to}} <!-- Link A-->
{{#link-to 'fav.top'}}Top{{/link-to}} <!-- Link B-->

<!-- Expected Output from "fav/index" -->
{{outlet}}
</script>

<script type="text/x-handlebars" id="fav/index">
All Favourites Content
</script>

<script type="text/x-handlebars" id="fav/top">
Top Favourites Content
</script>

<script type="text/x-handlebars" id="football">
Football Content
</script>

JS代码:这是我尝试过的

App.Router.map(function(){
this.resource('index', {path: '/'}, function(){
this.resource('fav', function(){
this.route('top');
this.route('last');
});
});
this.route('football');
});
App.IndexIndexRoute = Ember.Route.extend({
renderTemplate: function() {
this.render();
this.render("fav", {into: 'index'});
}
});
Output:===================================Here we have our applicationApplication's First ChildYour FavouritesLink ALink B===================================Omits the child outlet which should display content from "fav/index"Help Appreciated.

最佳答案

您可以在 IndexIndexRoute 中添加额外的渲染调用,

App.IndexIndexRoute = Ember.Route.extend({
renderTemplate: function() {
this.render();
this.render("fav", {into: 'index'});
this.render("fav/index", {into: 'fav'});
}
});

http://jsfiddle.net/7b8HT/

此外,您当然也可以使用 View 来获得类似的结果。

关于javascript - Ember 模板链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19247615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com