简体   繁体   English

在ember.js的模板中插入视图

[英]Inserting view in template in ember.js

Hello there i am following "lets learn ember" by José Mota in tuts premium. 您好,我正在关注JoséMota的“让我们学习余烬”话题。 I am stuck in a very strange situation. 我陷入了一个非常奇怪的情况。

I am at 9th video in the series where i am learning to create list view items and inserting that view in application template. 我在该系列的第9个视频中,我正在学习创建列表视图项并将该视图插入应用程序模板。 I exactly did what author did in the video, however the result doesn't show up in the screen. 我确实做了作者在视频中所做的事情,但是结果没有显示在屏幕上。 But in console the obejct is successfully added. 但是在控制台中,对象已成功添加。

I am creating a flash message view, whenever user add certain message the flash message should display at the top of the screen with fade in effect. 我正在创建一个Flash消息视图,每当用户添加某些消息时,该Flash消息应显示在屏幕顶部并具有淡入效果。

I have basically an alert view that handles fadein and out of the message, App.flashController controller which in turn extended from App.FlashController, which extends Ember.ArrayController, and App.FlashListView view. 我基本上有一个用于处理淡入和淡出消息的警报视图,App.flashController控制器又从App.FlashController扩展而来,后者又扩展了Ember.ArrayController和App.FlashListView视图。

Here is my code 这是我的代码

flash.js controller flash.js控制器

App.FlashController = Ember.ArrayController.extend();

App.flashController = App.FlashController.create({content: Ember.A()});

FlashListView code: FlashListView代码:

App.FlashListView = Ember.CollectionView.extend({
itemViewClass: "App.AlertView"
,   contentBindings: "App.flashController"
});

Alert view code 警报查看代码

App.AlertView = Ember.View.extend({
templateName: "_alert"
,   tagName: "div"
,   classNameBindings: ["defaultClass", "kind"]
,   defaultClass: "alert-box"
,   kind: null

,   click: function(){
    this.$().fadeOut(300, function(){ this.remove();});
}
,   didInsertElement: function(){
    this.$().hide().fadeIn(300);
}
});

here is the order of loading of the files 这是文件的加载顺序

<script src="js/app.js"></script>
    <script src="js/route/route.js"></script>
    <script src="js/controllers/bookmarks_controller.js"></script>
    <script src="js/controllers/bookmark_controller.js"></script>
    <script src="js/views/alert.js"></script>
    <script src="js/views/flash_list.js"></script>
    <script src="js/controllers/flash.js"></script>

And this is where the flash message should be displayed 这是应显示Flash消息的位置

<script type="text/x-handlebars" data-template-name="application">
        <div>
            <nav class="top-bar" data-options="is_hover:true">
                <ul class="title-area">
                    <li class="name">
                      <h1><a href="#">My Ember Site </a></h1>
                    </li>
                </ul>

                <section class="top-bar-section">
                    <ul class="right">
                        <li class="name">{{#linkTo "index"}}Home{{/linkTo}}</li>
                        <li>{{#linkTo "about"}}About{{/linkTo}}</li>
                        <li>{{#linkTo "about.team"}}About Team{{/linkTo}}</li>
                        <li>{{#linkTo "about.kshitiz"}}About Kshitiz{{/linkTo}}</li>
                        <li>{{#linkTo "bookmarks"}}Bookmarks{{/linkTo}}</li>
                    </ul>
                </section>
            </nav>
        </div>

        <div class="container">
            <div class="row">
                {{outlet}}
                {{view App.FlashListView}}
            </div>
        </div>
    </script>

_alert template code: _alert模板代码:

<script type="text/x-handlebars" data-template-name="_alert">
        {{view.content.message}}
    </script>

in browser when I write this command 在浏览器中,当我编写此命令时

App.flashController.pushObject(Ember.Object.create({message:"Hello!"})) App.flashController.pushObject(Ember.Object.create({message:“ Hello!”}}))

a class was returned 上课了

Class {message: "Hello!", constructor: function, toString: function, reopen: function, init: function…} 类{message:“ Hello!”,构造函数:function,toString:函数,reopen:函数,init:函数…}

But it doesnt show up in screen as in tutorial. 但是它不会像教程中那样显示在屏幕上。

I have no idea what went wrong and i am completely new to this ember.js world. 我不知道出了什么问题,并且我对这个ember.js世界是全新的。

There is a possible typo in App.FlashListView, should be singular contentBinding not plural contentBindings App.FlashListView中可能有错字,应为单数contentBinding而不是复数contentBindings

App.FlashListView = Ember.CollectionView.extend({
    itemViewClass: "App.AlertView"
,   contentBinding: "App.flashController"
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM