我有一個小的餘燼設置加載產品並顯示它們。因此,每個產品都有店面知道我想從產品頁面商店聯繫,但我不知道在哪裏我要告訴燼產品具有存儲emberjs中的嵌套對象
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'}
}
]
你能解釋一下什麼叫「告訴燼產品都有專賣店」,並分享你的API將返回的例子是什麼意思? –
我的目標是在呈現「App.Product」對象的模板中,它將知道產品中存在具有id的商店對象,因此它可以構建鏈接。 –