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
在Ember.js中使用json数据时更改PrimaryKey_Ember.js - Fatal编程技术网

在Ember.js中使用json数据时更改PrimaryKey

在Ember.js中使用json数据时更改PrimaryKey,ember.js,Ember.js,我正在制作一个Ember.js应用程序,它从xml文件获取帖子,并使用xml2json将其转换为json。Ember希望json文件中有一个“id”,但没有,我想改为“title” 这是我的密码 App.Router.map(function() { this.resource('posts'); this.resource('post', { path: '/posts/:post_id' }); }); App.PostsRoute = Ember.Route.extend({

我正在制作一个Ember.js应用程序,它从xml文件获取帖子,并使用xml2json将其转换为json。Ember希望json文件中有一个“id”,但没有,我想改为“title”

这是我的密码

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

App.PostsRoute = Ember.Route.extend({
  model: function() {
    var url = "/rss.xml";
    return Ember.$.get(url).then(function (xml) {
      var json = $.xml2json(xml);
        return json.channel.item.map(function(article) {
          article.body = article.description;
          return article;
        });
    });
  }
});
有一些古老的答案,但它们似乎不再有效。 我正在运行ember-1.5.1.js

我想不出App.PostRoute=Ember.Route.extend({
以及如何将“id”更改为“title”。

只需将资源段塞更改为title即可

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

App.PostRoute = Ember.Route.extend({
  model: function(params){
    /// $.get('/url' + params.title);
  }
});

谢谢。我觉得使用资源段塞没那么容易。我仍然无法使用PostRoute。我不知道在哪里放置“+参数标题”当我通过xml2json获取json文件时。我想我需要PostsRoute中的代码,但我不知道要更改什么。您需要在post路由中实现对服务器的某种调用,除非您计划将post资源作为posts资源的子资源。如果要这样做,您可以获取特定的post从posts资源的集合中删除。当前,您可以点击posts资源或post资源,而不点击另一个,这意味着您需要实现对服务器的调用,以获取路由模型钩子中请求的数据。