简体   繁体   中英

RactiveJS: How to sort table by computed value?

I'm new to ractive and looking at the table sort tutorial at https://ractive.js.org/tutorials/iterative-sections/#step-5

But what if I want to sort by a "computed" value, such as the output of:

{{#resources}}
    {{#if (type_id==1) }}
        {{name}}
    {{elseif parent_id!=15173}}
        {{name}}
    {{/if}}
{{/resources}}

or:

{{client.0.name}}

?

你可以通过使用带有compare函数参数的sort()来实现这一点 - 例如,array.sort(function(a,b){/ *为a和b生成计算值(基于你的模板逻辑)并返回比较结果新的价值});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM