我有一个小的 ember 集加载产品并显示它们。所以每个产品都有商店知道我想从产品页面链接到商店,但我不知道我必须在哪里告诉 ember 产品有商店
window.App = Ember.Application.create()
App.Router.map ->
@route 'products'
@route 'product', path: '/product/:product_id'
@route 'store', path: '/store/:store_id'
App.ProductsRoute = Ember.Route.extend
setupController: (controller)->
$.get('api', (response) ->
products = response.response.products //this object holds the store
.filter((p)-> p.gender == 'male')
.map ((p)-> App.Product.create(p))
controller.set('content', products)
)
controller.set 'name', 'Produkte'
App.Product = Ember.Object.extend
style: (->
"background-image:url('" + @get("image") + "')"
).property("url")
模板
script(type="text/x-handlebars", data-template-name="product")
<h1>{{page_title}}</h1>
<img {{bindAttr src="image"}}>
{{#linkTo "store" store}}Store{{/linkTo}}
产品 json
[
{
id: 1
name: 'product1',
gender: 'male'
store: {id: 1, name: 'store1'}
}
]