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
从API服务器返回的ember.js模型(POST op)不';在模型库中没有ID_Ember.js_Ember Data - Fatal编程技术网

从API服务器返回的ember.js模型(POST op)不';在模型库中没有ID

从API服务器返回的ember.js模型(POST op)不';在模型库中没有ID,ember.js,ember-data,Ember.js,Ember Data,我的REST Api成功地将记录持久化到服务器中,并使用ID将其返回给ember应用程序。但是,该ID不会作为模型的一部分插入存储中。检查屏幕盖 在控制器中: var post = this.store.createRecord('post'); post.set('title', this.get('title')); post.set('author', this.get('author')); post.set('body', this.get('body')); post.save();

我的REST Api成功地将记录持久化到服务器中,并使用ID将其返回给ember应用程序。但是,该ID不会作为模型的一部分插入存储中。检查屏幕盖

在控制器中:

var post = this.store.createRecord('post');
post.set('title', this.get('title'));
post.set('author', this.get('author'));
post.set('body', this.get('body'));
post.save(); // => POST to '/posts'
来自REST帖子的Chrome网络响应。请原谅我在图片上写的,哈哈。我希望你们能理解

服务器JSON响应:

{"post":
  {"id":"13",
   "title":"i",
   "author":"i",
   "body":"i"
  }
}
我不想从服务器重新加载所有数据并使用ID更新posts表。我想要的是,每次将posts插入服务器时,该表都将使用新条目和ID动态更新,以便可以在具有此路由的子视图中将其视为单个post,例如:

http://localhost/embercliapp/#/posts/13
但是,将记录持久化到rest服务器后,URL如下所示:

http://localhost/embercliapp/#/posts/null
更新

重新适应

import DS from 'ember-data';

export default DS.RESTAdapter.extend({
   namespace: 'api/api-server' //node.js ember mock api
});
更新2:

博思商学院

      <div class="table-responsive">
        <table class="table table-striped table-hover table-bordered">
          <thead>
            <tr>
              <th>Index</th>
              <th>Title</th>
              <th>Author</th>
              <th>Body</th>
              <th>Delete</th>
            </tr>
          </thead>

          <tbody>
            {{#each}}
              <tr>
                <td class="id-column">
                </td>
                <td>
                  {{#link-to 'post' this}}
                    {{title}}
                  {{/link-to}}
                </td>
                <td>{{author}}</td>
                <td>{{body}}</td>
                <td><a href="" {{action 'delete' this}}>X</a></td>
              </tr>
            {{/each}}
          </tbody>
        </table>
      </div>
      {{outlet}}

您正在使用自定义序列化程序或适配器吗?我正在使用RestaAdapter with ember cli http mock REST APIs实际模型是否缺少其ID,或者只是显示空ID的模板?可能模型上的ID正在设置,但模板没有正确观察ID。如何检查?我只将模型属性放在posts.hbs模板中。回答uppdated with posts.hbshow我是否从post.save()获取json响应,以便调查其ID?
import Ember from 'ember';

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

Router.map(function() {
  this.route('application');                    
  this.resource('posts', function() { //CRUD - read
    //child route
    this.resource('post', { path: ':post_id' }); //CRUD - update
    this.resource('new'); //CRUD - create
    this.resource('delete'); //CRUD - delete
  });
  this.route('about');
  this.route('login');  
});

export default Router;