Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/67.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
Javascript 余烬数据复制记录_Javascript_Ruby On Rails_Node.js_Ember.js_Ember Data - Fatal编程技术网

Javascript 余烬数据复制记录

Javascript 余烬数据复制记录,javascript,ruby-on-rails,node.js,ember.js,ember-data,Javascript,Ruby On Rails,Node.js,Ember.js,Ember Data,我使用的是余烬数据#金丝雀,它在从商店查找记录时有一个严重的错误 文件:router.js this.resource('games', function() { this.route('game', { path: '/:game' }); }); App.GamesRoute = Ember.Route.extend({ model: function() { // request: GET /api/games // response:

我使用的是余烬数据#金丝雀,它在从商店查找记录时有一个严重的错误

文件:router.js

this.resource('games', function() {
    this.route('game', { path: '/:game' });
});
App.GamesRoute = Ember.Route.extend({
    model: function() {

        // request: GET /api/games
        // response: { games: [
        //               { id: 1, slug: lym, name: lose your marbles }
        // ] }
        return this.store.find('game');
    }
});
App.GamesGameRoute = Ember.Route.extend({
    model: function(params) {
        // this query causes bogus data to show up.
        // request: GET /api/games/lym
        // response: { game: { id: 1, slug: lym, name: lose your marbles } }
        return this.store.find('game', params.game);

    },

    serialize: function(game) {
        return { game: game.get('slug') };
    }
});
App.Game = DS.Model.extend({
    slug: DS.attr('string'),
    name: DS.attr('string'),
});
文件:games\u route.js

this.resource('games', function() {
    this.route('game', { path: '/:game' });
});
App.GamesRoute = Ember.Route.extend({
    model: function() {

        // request: GET /api/games
        // response: { games: [
        //               { id: 1, slug: lym, name: lose your marbles }
        // ] }
        return this.store.find('game');
    }
});
App.GamesGameRoute = Ember.Route.extend({
    model: function(params) {
        // this query causes bogus data to show up.
        // request: GET /api/games/lym
        // response: { game: { id: 1, slug: lym, name: lose your marbles } }
        return this.store.find('game', params.game);

    },

    serialize: function(game) {
        return { game: game.get('slug') };
    }
});
App.Game = DS.Model.extend({
    slug: DS.attr('string'),
    name: DS.attr('string'),
});
文件:game_route.js

this.resource('games', function() {
    this.route('game', { path: '/:game' });
});
App.GamesRoute = Ember.Route.extend({
    model: function() {

        // request: GET /api/games
        // response: { games: [
        //               { id: 1, slug: lym, name: lose your marbles }
        // ] }
        return this.store.find('game');
    }
});
App.GamesGameRoute = Ember.Route.extend({
    model: function(params) {
        // this query causes bogus data to show up.
        // request: GET /api/games/lym
        // response: { game: { id: 1, slug: lym, name: lose your marbles } }
        return this.store.find('game', params.game);

    },

    serialize: function(game) {
        return { game: game.get('slug') };
    }
});
App.Game = DS.Model.extend({
    slug: DS.attr('string'),
    name: DS.attr('string'),
});
文件game\u model.js

this.resource('games', function() {
    this.route('game', { path: '/:game' });
});
App.GamesRoute = Ember.Route.extend({
    model: function() {

        // request: GET /api/games
        // response: { games: [
        //               { id: 1, slug: lym, name: lose your marbles }
        // ] }
        return this.store.find('game');
    }
});
App.GamesGameRoute = Ember.Route.extend({
    model: function(params) {
        // this query causes bogus data to show up.
        // request: GET /api/games/lym
        // response: { game: { id: 1, slug: lym, name: lose your marbles } }
        return this.store.find('game', params.game);

    },

    serialize: function(game) {
        return { game: game.get('slug') };
    }
});
App.Game = DS.Model.extend({
    slug: DS.attr('string'),
    name: DS.attr('string'),
});
当我访问
/games
ember inspector数据选项卡时,显示1个已加载的游戏

`id`    `slug`    `name`
 1       lym       lose your marbles
`id`    `slug`         `name`
 1       lym            lose your marbles
 lym     undefined      undefined
当我访问
/games/lym
ember inspector数据选项卡时,显示2个已加载的游戏

`id`    `slug`    `name`
 1       lym       lose your marbles
`id`    `slug`         `name`
 1       lym            lose your marbles
 lym     undefined      undefined

第二个数据显然是假的。我不知道它是从哪里来的,这给我带来了麻烦。

当你调用
this.store.find('game',params.game)
时,余烬数据认为
lym
是一个id,并用这个
id
创建空记录。然后它接收具有实际记录的有效负载,并以id=1进行存储


基本上,在
store.find
中,你应该使用实际id,而不是slug,即使你的API支持slug。

非常感谢你,现在我了解了这个问题,为了解决这个问题,我可以在路由上使用
序列化
反序列化
钩子,我认为它们可能会解决这个问题。这解决了问题,.现在我需要在url中使用slug,在
模型中
hook
参数中
是slug,我不能在
存储中使用实际id。查找
,因为我有slug而不是id。我如何克服这一问题?有没有类似于
store.findBySlug
this.store.find('game',{slug:params.game})
aha,我已经尝试过了,它用查询参数
/games?slug='bla'
请求,但我需要
/games/bla