gpt4 book ai didi

javascript - 链接标记在 Ember Js 中不起作用

转载 作者:行者123 更新时间:2023-11-30 17:58:11 25 4
gpt4 key购买 nike

这是模型

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

最佳答案

随着将对象传递给 linkTo 中的 sources 路由,

App.SourcesRoute 中定义 serialize 方法。

模板:

{{#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 };
}
});

关于javascript - 链接标记在 Ember Js 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17690886/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com