6
我想知道是否可以向計算屬性中添加參數。到目前爲止,我嘗試過的所有東西都會導致錯誤,並且沒有發現任何問題我想使用未包含在我的模型中的值來構建URL。Ember使用參數計算的屬性
我正在尋找的東西,應該是這樣的:
// App.js
App.Image = DS.Model.extend({
image_path_sh: DS.attr(), // image.jpg
image_size_nm: DS.attr(), // 234234
image_alt_sh: DS.attr(), // My image
image_abs_url: function(width, height) {
return "http://localhost/images/" + this.get('image_path_sh') + "/" + width "x" + height
}.property('image_path_sh')
});
// index.html
// I know this doesn't work, but I'd like to have something that easy to use
{{#each image}}
<img src="{{image_abs_url 250 250}}" alt="{{image_alt_sh}}" />
{{/each}}
我的服務器將返回被調整大小的圖像。我不想把它放在我的數據庫中,因爲它們不是固定值。
我希望這樣的事情,我不認爲你可以做到這一點,雖然,也許'Ember.Handlebars.helper'將是最接近它。 – iConnor