我通过迭代在 Vue 中创建以下列表payeefundingAccountList
。
<cx-select id="payee-select" @cxChange="changeSelectedPayee" class="dropdown">
<option value="" disabled selected>Choose payment account</option>
<option
v-for="(account, index) in payeefundingAccountsList"
:value="index"
:key="index"
:checked="index === paymentAccountSelectedIndex"
>{{ account.bankName }}...{{account.displayAccountNumber}}({{account.accountType}})</option>
<option
v-bind:key="payeefundingAccountsList.length + 1"
v-bind:value="payeefundingAccountsList.length +1"
>Add a payment account</option>
</cx-select>
我需要按属性对这个列表进行排序account.accountType
。此属性可以有两个值:CHECKING
或者SAVINGS
我需要将具有 accountType 的项目CHECKING
排序到顶部。
我正在尝试创建一种在迭代之前运行列表的方法,例如:
v-for="(account, index) in sortByAccountType(payeefundingAccountsList)"
...但是,我在从该sortByAccountType
方法中获得任何结果时遇到了一些麻烦。我觉得我的方法很遥远。如果有人能指出我正确的方向,我会欣喜若狂。