1

这是模型

App.Store = DS.Store.extend({
   revision: 12,
   adapter: DS.FixtureAdapter
});

App.Markets = DS.Model.extend({
    ids: DS.attr("string"),
    name: DS.attr("string"),
    created: DS.attr("string")
});

App.Markets.FIXTURES = [
    {ids:"312", name:"joy", created:"2012/1/1"},
    {ids:"412", name:"adel", created:"2012/1/2"},
    {ids:"512", name:"john", created:"2012/1/3"}
]; 

App.Sources = DS.Model.extend({
   source_channel: DS.attr("string"),
   handle: DS.attr("handle")
});

App.Sources.FIXTURES = [
    {source_channel:"sc1", handle: "hn1"},
    {source_channel:"sc2", handle: "hn2"}
]; 

这是路线。

var App = Ember.Application.create();

App.Router.map(function() {
    this.resource('markets', {path: '/markets'}, function() {
        this.resource("sources", { path: "/:market_id" });
    });                                                          
});

App.MarketsRoute = Ember.Route.extend({
    model: function () {
        return App.Markets.find();
    }
});

App.SourcesRoute = Ember.Route.extend({
    model: function(){
        return App.Sources.find();
    }
});

这是模板

<script type="text/x-handlebars" id="_sources">
  {{#each sources in content}}
    <span>{{sources.handle}}</span>
    <span>{{sources.sources_channel}}</span>
  {{/each}}

</script>

<script type="text/x-handlebars" id="markets">
    {{#each markets in content }}
        {{#linkTo 'sources' markets.ids class="test" }}<span>Source</span>{{/linkTo}}
        <span>{{markets.name}}</span>
        <span>{{markets.created}}</span>

    {{/each}}

    <div class="sources">
        {{partial "sources"}}
    </div>
</script>  

当我去 时/#/markets,我可以看到市场列表。这是对的。

专注于{{#linkTo 'sources' markets.ids class="test" }}Source{{/linkTo}}市场模板。

在这里,markets.ids行不通。/#/markets/markets_id当我点击链接时,我想去。

4

2 回答 2

1

你想linkTo 'sources' markets改用。即: - 将每个循环中的模型传递给`linkTo。

注意:关于您的命名约定。Ember 喜欢模型是单数的,Routes/Controllers 是复数还是单数,这取决于路由是否指向一个或多个模型。

编辑:澄清。

改成linkTo这个,

{{#linkTo 'sources' markets class="test" }}<span>Source</span>{{/linkTo}}
于 2013-07-17T04:10:04.227 回答
1

随着将对象传递到 中的sources路线linkTo

serialize您的App.SourcesRoute.

模板:

{{#linkTo 'sources' markets class="test" }}<span>Source</span>{{/linkTo}}

路线:

 App.SourcesRoute = Ember.Route.extend({
    model: function(){
        return App.Sources.find();
    },
    serialize: function(model) {
        return { market_id: model.ids };
    }
});
于 2013-07-17T05:13:23.717 回答