如何访问Ember.computed.sort中的组件属性

时间:2019-03-17 09:49:44

标签: javascript ember.js ember-cli

在Ember 1.13中,我有一个使用Ember.computed.sort的组件:

function custom_single_price_html() {
global $woocommerce,$product, $post;
if ( $product->is_type('simple')) {
$reg_price = $product->get_regular_price();
//working fine for this condition
...
...
}

elseif ( $product->is_type('variable') ) {
$min_price = $product->get_variation_price('min', true);
$max_price = $product->get_variation_price('max', true);
$display_price_min_max = '<span class="sale-price">'.wc_price($min_price).' - '.wc_price($max_price). '</span>';

return $display_price_min_max;
}

else {
return;
}

}

add_action('woocommerce_get_price_html', 'custom_single_price_html');

我需要访问组件的columnList属性以自定义提供给Ember.computed.sort的比较函数的行为。如何在上面的代码指示的位置访问比较函数内部的columnList?

1 个答案:

答案 0 :(得分:0)

如果cloumnList属性位于与您使用component相同的Ember.computed.sort下,则只需使用this.get('columnList');访问columnList属性

...
sortedItems: Ember.computed.sort("allItems", function(a, b) {
  this.get('columnList');
}),
...

ember-twiddle示例。