-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I'm building a web app that has a need to show a list of news story headlines. Ideally i'd like a list of entries where each entry shows: A logo for the news story source (like the newspaper logo) The headline A brief description that includes a "Read more..." link that when clicked opens up another browser tab showing the story in full.
What would be the best ZK component to use for this?
Depends on a number of factors (project pattern, page structure, presentation, etc...) but that sounds like a good case for templating.
I'd make a simple vlayout containing a collection of "newscard", and pass variables such as "imageSrc (if you want different logo for each news), titleTxt, mainTxt, readMoreUrl,..."
newscard can be many things, but I'd go for simple components (div, image, label, [a href="${url}"] for the "read more" link, possibly hlayout/vlayout for relative positioning).
With the newscard template ready, most basic case would be collection binding with anything that lets you instantiate a template with variables (fragment, template, include, executions.createComponents(), ...).
I wouldn't recommend a composite (such as macro-component, or custom component) unless each newscard is behavior-heavy with a bunch of events for each card. Would work, but that's more work that you don't need, unless you have a control-heavy or event-heavy newscard :)
With MVC, I'd just make a newscard.zul snippet as a separate zul file, with variables for the relevant stuff, then iterate through my news model doing Executions.createComponents or createComponentsDirectly while passing the data for each newscard.
With ZK8/MVVM, that's a good use-case for shadow elements (forEach / template is a perfect for that situation. If news are updated in real-time, using a ListModel<newscarddata> as source for the <foreach> makes it really easy to render / update). Of course, good old children="@load(vm.model)" binding with template is still an option.
Asked: 2019-03-03 21:31:46 +0800
Seen: 8 times
Last updated: Mar 05 '19