本文整理汇总了TypeScript中@soil/dom.h.output方法的典型用法代码示例。如果您正苦于以下问题:TypeScript h.output方法的具体用法?TypeScript h.output怎么用?TypeScript h.output使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@soil/dom.h
的用法示例。
在下文中一共展示了h.output方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: title
.then(([rdis, foodDetails]) => {
title(foodDetails.Long_Desc)
const extendedRdis = rdis
.map(rdi => {
const nutr = foodDetails.nutrients.find(nutr => nutr.NutrDesc === rdi.NutrDesc)
return !nutr ? undefined : {
...rdi,
...nutr,
pct: pct(nutr.Nutr_Val, rdi.value)
}
})
.filter(pct => pct !== undefined) as ExtendedRdi[]
const overallPct = pct(
extendedRdis.map(rdi => Math.min(rdi.pct, 100)).reduce(add, 0),
100 * extendedRdis.length
)
const $sortByNameBtn = h.a({
title: 'Sort nutrients alphabetically',
onclick: () => renderNutrientsSortedByName()
}, [icon('sort-alpha-down')])
const $sortByPctBtn = h.a({
title: 'Sort nutrients by RDI coverage',
onclick: () => renderNutrientsSortedByPct()
}, [icon('sort-amount-down')])
const $nutrientList = h.ul({})
if ((localStorage.getItem('nutrients_order') || 'alpha') === 'alpha') {
renderNutrientsSortedByName()
} else {
renderNutrientsSortedByPct()
}
const $foodDetails = h.div({className: 'food-details'}, [
h.h1({}, [
foodGroupCircle(foodDetails),
foodDetails.Long_Desc,
h.output({}, [
h.span({title: 'Overall percentage of nutrients covered by 100 grams of this food'}, [overallPct.toFixed(2) + nbsp + '%']),
', ',
100 + nbsp + 'g'
]),
h.a({
href: 'https://www.google.com/search?tbm=isch&q=' + encodeURIComponent(foodDetails.Long_Desc),
title: 'See in Google Images'
}, [icon('images')]),
h.a({
onclick: () => $findFoodsModal.open(),
title: 'Find details of a different food'
}, [icon('search')]),
$sortByNameBtn,
$sortByPctBtn,
clear()
]),
$nutrientList
])
document.body.appendChild($foodDetails)
function renderNutrientsSortedByName() {
localStorage.setItem('nutrients_order', 'alpha')
$sortByPctBtn.classList.remove('disabled')
$sortByNameBtn.classList.add('disabled')
$nutrientList.innerHTML = ''
extendedRdis
.sort((a, b) => {
const nameA = a.display_name || a.NutrDesc
const nameB = b.display_name || b.NutrDesc
return nameA > nameB ? 1 : -1
})
.forEach(rdi => $nutrientList.appendChild(nutrientItem(rdi)))
}
function renderNutrientsSortedByPct() {
localStorage.setItem('nutrients_order', 'pct')
$sortByPctBtn.classList.add('disabled')
$sortByNameBtn.classList.remove('disabled')
$nutrientList.innerHTML = ''
extendedRdis
.sort((a, b) => a.pct > b.pct ? -1 : 1)
.forEach(rdi => $nutrientList.appendChild(nutrientItem(rdi)))
}
})