简体   繁体   English

在Ember模板中呈现{{content}}的问题

[英]Problems rendering {{content}} in Ember Template

i have a problem using ember 1.1.2. 我使用ember 1.1.2时遇到问题。

notes.hbs notes.hbs

<ul class="note-list">
{{#each itemController="note"}}
    <li class="note">
        <div class="note__inner note__inner--edit">
            <a href="#" {{action editNote}}><img src="images/pencil-icon.svg" /></a>
            <a href="#" {{action deleteNote}}><img src="images/trash-can-icon.svg" /></a>
        </div>
        <div class="note__inner note__inner--content">
            <h3>{{title}}</h3>
            {{content}}
        </div>
    </li>
{{/each}}
</ul>

router.js router.js

YeoApp.Router.map(function () {
    this.resource("notes", { path: "/" } );
});

YeoApp.NotesRoute = Ember.Route.extend({
    model: function() {
        return this.store.find("note");
    }
});

note_controller.js note_controller.js

YeoApp.NoteController = Ember.ObjectController.extend({
    actions: {
        editNote: function() {
            console.log("edit note called");
        },
        deleteNote: function() {
            var note = this.get('model');
            console.log(note);
            note.deleteRecord();
            note.save();
        }
    }
});

store.js store.js

YeoApp.Store = DS.Store.extend({
    adapter: DS.FixtureAdapter.extend()
});

model_note.js model_note.js

YeoApp.Note = DS.Model.extend({
    title: DS.attr("string"),
    content: DS.attr("string")
});

YeoApp.Note.FIXTURES = [
    {
        id: 1,
        title: "red title",
        content: "red content here"
    },
    // .. snip ..
];

If i have itemController="note" in the template then instead of rendering {{content}} of the model it renders something like this: <YeoApp.Note:ember352:6> (YeoApp is the app name). 如果我在模板中有itemController="note" ,那么它不会渲染模型的{{content}},而是呈现如下内容: <YeoApp.Note:ember352:6> (YeoApp是应用程序名称)。 The {{title}} is properly rendered! {{title}}已正确呈现! If i remove the itemController from the hbs-file then the content of the model is rendered, but the editNote and deleteNote actions aren't called in the controller if i click on them. 如果我从hbs文件中删除itemController,则呈现模型的内容,但如果我单击它们,则不会在控制器中调用editNote和deleteNote操作。

Of course i could rename the content-property, but i think i have made a mistake somewhere. 当然我可以重命名内容属性,但我想我在某个地方犯了一个错误。 What have i do to render {{content}} properly? 我该怎么做才能正确呈现{{content}}?

Thanks in advance, any help is appreciated. 在此先感谢,任何帮助表示赞赏。

content and model are synonyms in the template, use model.content or something like this content和model是模板中的同义词,使用model.content或类似的东西

{{#each item in controller itemController="note"}}
    <li class="note">
        <div class="note__inner note__inner--edit">
            <a href="#" {{action editNote}}><img src="images/pencil-icon.svg" /></a>
            <a href="#" {{action deleteNote}}><img src="images/trash-can-icon.svg" /></a>
        </div>
        <div class="note__inner note__inner--content">
            <h3>{{item.title}}</h3>
            {{item.model.content}}
        </div>
    </li>
{{/each}}

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

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