简体   繁体   English

计算属性未在aurelia中更新

[英]Computed property not updating in aurelia

Currently I try to reevaluate my "enabled" property but its not re-computed after I change either pages or pageIndex. 目前我尝试重新评估我的“启用”属性,但在我更改页面或pageIndex后它没有重新计算。

page.js page.js

export class Test {
    pageIndex = 0;
    pages = 2;

    constructor() {
        this.items = [
            {title:"Prev.", enabled:this.prevAvailable},
            {title:"Next", enabled:this.nextAvailable}
        ];
    }

    get prevAvailable() {
        return this.pageIndex > 0;
    }

    get nextAvailable}() {
        return this.pageIndex < this.pages;
    }
}

page.html page.html中

<template>
    <ul>
        <li repeat.for="item of items">
            <button if.bind="item.enabled">
                ${item.title}
            </button>
        </li>
    </ul>
</template>

How is the normal way to achive this behaviour for a standard paging control? 如何为标准分页控件实现此行为的正常方法是什么? I try to disable the "next" button if on last page. 如果在最后一页,我尝试禁用“下一步”按钮。

I appreciate any help. 我感谢任何帮助。

Here's the pager custom element I used in this project (scroll to bottom to see the pager). 这是我在这个项目中使用的寻呼机自定义元素(滚动到底部查看寻呼机)。

呼叫器

pager.html pager.html

<template>
  <ul class="pagination" show.bind="pageCount > 1">
    <li class="${pageIndex === 0 ? 'disabled' : 'waves-effect'}">
      <a href="#" click.delegate="setPage(0)"><i class="mdi-navigation-chevron-left"></i></a>
    </li>
    <li repeat.for="p of pageCount" class="${p === $parent.pageIndex ? 'active' : 'waves-effect'}">
      <a href="#" click.delegate="$parent.setPage(p)">${p + 1}</a>
    </li>
    <li class="${pageIndex === pageCount - 1 ? 'disabled' : 'waves-effect'}">
      <a href="#" click.delegate="setPage(pageCount - 1)"><i class="mdi-navigation-chevron-right"></i></a>
    </li>
  </ul>
</template>

pager.js pager.js

import {bindable} from 'aurelia-framework';

export class Pager {
  @bindable pageIndex;
  @bindable pageCount;
  @bindable setPage;
}

Here's how the pager element is used: 以下是pager元素的使用方式:

order-list.html 为了-list.html

<pager page-count.bind="pageCount"
       page-index.bind="pageIndex"
       set-page.call="setPage($event)">
</pager>

EDIT 10/14/2015 编辑10/14/2015

Here's a bootstrap pager- works a little differently but it's usage is the same, no view-model required: 这是一个bootstrap pager-工作方式略有不同,但它的用法是相同的,不需要视图模型:

<template bindable="pageCount, pageIndex, setPage">
  <ul ref="pager" class="pagination" if.bind="pageCount > 1"
      offset.bind="pageIndex + 5 > pageCount && pageCount > 5 ? (pageCount - 5) : (3 * (pageIndex - 1 - (pageIndex - 1) % 3) / 3)">
    <li class="${pageIndex === 0 ? 'disabled' : ''}">
      <a href="#" aria-label="Previous" click.delegate="setPage(0)">
        <span aria-hidden="true">&laquo;</span>
      </a>
    </li>
    <li repeat.for="p of pageCount > 5 ? 5 : pageCount" class="${p + $parent.pager.offset === $parent.pageIndex ? 'active' : ''}">
      <a href="#" click.delegate="$parent.setPage(p + $parent.pager.offset)">${p + $parent.pager.offset + 1}</a>
    </li>
    <li class="${pageIndex === pageCount - 1 ? 'disabled' : ''}">
      <a href="#" aria-label="Previous" click.delegate="setPage(pageCount - 1)">
        <span aria-hidden="true">&raquo;</span>
      </a>
    </li>
  </ul>
</template>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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