如何只略微打印前几个项目?

时间:2016-10-10 06:45:53

标签: aem sightly htl

我在列表中有10个项目。我想只打印列表中的前5个项目。如何使用data-sly-list

添加条件

1 个答案:

答案 0 :(得分:2)

您可以将sly-test<ul data-sly-list="${mylist}"> <li data-sly-test="${itemList.index < 5}">${itemList}</li> </ul> this与数据一起使用 - describe('Async Actions', () => { it('should upload supplier and dispatch ADD_SUPPLIER', (done)=> { /*Let Mocha know that this is asnyc test*/ //mock a store const store = createMockStore({}); //test supplier var testSupplier = { name: "new supplier", fact_sheet: "fact sheet", liability_sheet: "liability sheet", group: "group", service_lines: null, policies: null, rate_periods: null, rate_costs: null, contracts: null, cancellation_terms: null, deposit_terms: null, commission: 22, creation_date: moment().unix(), country: "SA", region: "Capetown", email: "mail@m.com", telephone: "2797179", website: "ww.ww.ww", category: "cat", rating: 100 }; //Do the async action store.dispatch(actions.startAddSupplier(testSupplier.name, testSupplier.fact_sheet, testSupplier.liability_sheet, testSupplier.group, testSupplier.commission, testSupplier.country, testSupplier.region, testSupplier.email, testSupplier.telephone, testSupplier.website, testSupplier.category, testSupplier.rating)).then( () => { /*Assertions*/ const actions = store.getActions(); //returns array of all actions fired on store expect(actions).toInclude({ type: 'ADD_SUPPLIER' }); /*done to show test is done*/ done(); }).catch(done);//if done is called with args it is assumed the test has failed }); }); ,如:

FAILED TESTS:
  Actions
    Supplier Actions
      Async Actions
        ✖ should upload supplier and dispatch ADD_SUPPLIER
          Chrome 53.0.2785 (Mac OS X 10.12.0)
        Error: Expected [ { supplier: { cancellation_terms: null, category: 'cat', commission: 22, contracts: null, country: 'SA', creation_date: 1476087460, deposit_terms: null, email: 'mail@m.com', fact_sheet: 'fact sheet', group: 'group', id: '-KThemyhqrmDHuF_PV2H', liability_sheet: 'liability sheet', name: 'new supplier', policies: null, rate_costs: null, rate_periods: null, rating: 100, region: 'Capetown', service_lines: null, telephone: '2797179', website: 'ww.ww.ww' }, type: 'ADD_SUPPLIER' }, { key: '-KThemyhqrmDHuF_PV2H', type: 'SET_CURR_SUPPLIER' } ] to include { type: 'ADD_SUPPLIER' }
            at Object.assert [as default] (eval at <anonymous> (/Users/zacck/Documents/www/jtx/app/tests/actions/actions.test.jsx:1231:2), <anonymous>:20:9)
            at Expectation.toInclude (eval at <anonymous> (/Users/zacck/Documents/www/jtx/app/tests/actions/actions.test.jsx:1129:2), <anonymous>:190:26)
            at eval (eval at <anonymous> (/Users/zacck/Documents/www/jtx/app/tests/actions/actions.test.jsx:47:2), <anonymous>:129:42)

或者,如果您的列表很大并且您不想迭代它,那么您可以定义一个Use-API帮助程序,它创建一个只包含前5个所需元素的新列表。