0

这是代码说明:http: //jsbin.com/uzapuy/1/edit

我希望能够通过 URL访问测试,如下所示:http: //jsbin.com/uzapuy/1#/test/2 因为条目可能已经存在于客户端,我想首先检查它,并且只有当它缺少 fetch从服务器端。如果没有 DS.Store,这可能吗?

4

1 回答 1

0

In your TestRoute, can you not do something like:

App.TestRoute = Ember.Route.extend({

    model: function(params) {

        // Find your controller that has the "fetch" method.
        var testController = this.controllerFor('test');

        // Check if there's an existing model with this ID.
        var existingModel  = testController.find('id', params.id);

        // Determine if we found a model or not.
        if (existingModel) {

            // If we found an existing model, then we can set this as the model.
            return existingModel;

        }

        // Otherwise we'll fetch it from the server.
        return testController.fetch(params.id);
    }

});

Also, bear it in mind that in your code, the test variable is undefined:

var tests = App.Test.create({id: id, name: 'fetched ' + id});
self.set('content', test);

You're after tests, I assume.

于 2013-02-09T12:40:03.767 回答