小编bro*_*003的帖子

带有cli的ember.js中的夹具数据在哪里

我正在尝试在使用cli生成的ember应用程序中使用fixture数据.我找不到我的数据.检查员显示我有一个名为post的模型,但没有任何内容.我不确定为什么它不起作用所以发布我认为相关的文件...

车型/ post.js

var Post = DS.Model.extend({
    title: DS.attr('string'),
    content: DS.attr('string'),
    publishDate: DS.attr('date')
});

Post.reopenClass({
    FIXTURES: [
        {
            id: 1,
            title: "Writing a blog in Ember",
            content: "I am writting a blog",
            publishDate: "05/22/2104"
        },
        {
            id: 2,
            title: "Writing a blog in Ember",
            content: "I am writting a blog",
            publishDate: "05/22/2104"
        }
    ]
});

export default Post;
Run Code Online (Sandbox Code Playgroud)

router.js

var Router = Ember.Router.extend({
  location: ENV.locationType
});

Router.map(function() {
    this.resource('posts', { path: '/' });
});

export default Router;
Run Code Online (Sandbox Code Playgroud)

路线/ index.js

export …
Run Code Online (Sandbox Code Playgroud)

javascript ember.js

7
推荐指数
1
解决办法
3743
查看次数

嵌套资源在ember.js中,使用夹具数据向帖子添加注释

我正在尝试用Ember写一个简单的博客.我无法弄清楚如何在帖子资源中嵌套评论资源.(我使用ember-cli生成应用程序)

/app/router.js

var Router = Ember.Router.extend({
  location: ENV.locationType
});

Router.map(function() {
    this.resource('posts', { path: '/' }, function() {
        this.resource('post', { path: 'posts/:post_id' }, function() {
            this.resource('comments');
        });
    });
});

export default Router;
Run Code Online (Sandbox Code Playgroud)

/app/templates/posts.hbs

<div class="col-xs-3">
    <h2>Posts</h3>
    {{#each}}
        <h4>{{#link-to 'post' this}}{{title}}{{/link-to}}</h4>
    {{/each}}
</div>
<div class="col-xs-9">
    {{outlet}}
</div>
Run Code Online (Sandbox Code Playgroud)

/app/templates/post.hbs

<h2>
    {{#if isEditing}}
        {{input value=title}}
    {{else}}
        {{title}}
    {{/if}}
</h2>
<p>
    {{#if isEditing}}
        {{textarea value=body}}
    {{else}}
        {{body}}
    {{/if}}
</p>
<p>
    {{publishDate}}
</p>

{{#if isEditing}}
    <button {{action 'doneEditing'}}>Save</button>
{{else}}
    <button {{action 'edit'}}>Edit</button>
{{/if}}

{{!-- Should …
Run Code Online (Sandbox Code Playgroud)

ember.js ember-data

7
推荐指数
1
解决办法
3936
查看次数

如何在数组控制器中声明项目控制器 - ember.js

我正在尝试编写Todo应用程序(使用ember-cli).当我在todos资源下添加活动和完整路由时,我的项目控制器停止工作.在我使用Array控制器中的itemController设置我的Object控制器之前.

router.js

import Ember from 'ember';

var Router = Ember.Router.extend({
    location: TodoMVCENV.locationType });

Router.map(function() {
    this.resource('todos', { path: '/' }, function() {
        this.route('active');
        this.route('complete');
    }); 
});

export default Router;
Run Code Online (Sandbox Code Playgroud)

控制器/ todos.js

import Ember from 'ember';

var TodosController = Ember.ArrayController.extend({
    actions: {
        createTodo: function() {
            // Get the todo title set by the "New Todo" text field
            var title = this.get('newTitle');

            // Create the new Todo model
            var todo = this.store.createRecord('todo', {
                title: title,
                isCompleted: false
            });

            // Clear the "New …
Run Code Online (Sandbox Code Playgroud)

ember.js

7
推荐指数
1
解决办法
4294
查看次数

标签 统计

ember.js ×3

ember-data ×1

javascript ×1