ember g route passing-properties-to-component
ember g component passing-properties-to-component
調用組件的模板,傳入兩個位置參數,分別是item.title、item.body。
!-- apptemplatespassing-properties-to-component.hbs --
{{#each model as item}}
!-- 傳遞到組件blog-post第一個參數為數據的title值,第二個為body值 --
{{passing-properties-to-component item.title item.body}}
{{each}}
準備需要顯示的數據。
approutespadding-properties-to-component.js
import Ember from 'ember';
export default Ember.Route.extend({
model function() {
return [
{ id 1, title 'Bower dependencies and resolutions new', body In the bower.json file, I see 2 keys dependencies and resolutionsWhy is that so },
{ id 2, title 'Highly Nested JSON Payload - hasMany error', body Welcome to the Ember.js discussion forum. We're running on the open source, Ember.js-powered Discourse forum software. },
{ id 3, title 'Passing a jwt to my REST adapter new ', body This sets up a binding between the category query param in the URL, and the category property on controllerarticles. }
];
}
});
在組件類中指定位置參數的名稱。
appcomponentspadding-properties-to-component.js
import Ember from 'ember';
export default Ember.Component.extend({
指定位置參數的名稱
positionalParams ['title', 'body']
});
更多建議: