我有一個重複的卡型自定義元素綁定到從api拉出的JSON數據。我目前創建數據並將其綁定到這些卡片上的方法是有效的,但所有與它有關的信息都尖叫着「摺疊」。 Aurelia有沒有更好的方法來實現這些目標?Aurelia,自定義元素上的長長的可綁定列表。重構?
我現在的自定義元素的圖案看起來像這樣
尋呼機view.html
<!-- Loop through the JSON task-data (each card contains the chosen task-data to display) -->
<template repeat.for="task of pageData[currentPage - 1]">
<!--Bind each tasks data to a card as we loop-->
<card-commit
task-data.bind="task"
task-id.bind="task.ID"
task-name.bind="task.name"
project-id.bind="task.project.ID"
project-name.bind="task.project.name"
assigned-to.bind="task.assignedTo.name"
successors.bind="task.successors"
commit-status.bind="task.commitStatus"
planned-start-date.bind="task.plannedStartDate"
planned-comp-date.bind="task.plannedCompletionDate"
duration.bind="task.duration"
actual-start-date.bind="task.actualStartDate"
commit-date.bind="task.commitDate"
condition.bind="task.condition"
constraint.bind="task.taskConstraint"
constraint-date.bind="task.constraintDate"
status.bind="task.status"
note.bind="task.lastNote"
note-text.bind="task.lastNote.noteText"
note-entry-date.bind="task.lastNote.entryDate"
note-avatar-download-url.bind="task.lastNote.owner.avatarDownloadURL"
note-owner-name.bind="task.lastNote.owner.name"
actual-completion-date.bind="task.actualCompletionDate"
></card-commit>
</template>
卡commit.ts
import {bindable, inject} from 'aurelia-framework';
export class CardCommit {
@bindable public taskData;
@bindable public taskId;
@bindable public taskName;
@bindable public projectId;
@bindable public projectName;
@bindable public assignedTo;
@bindable public successors;
@bindable public commitStatus;
@bindable public plannedStartDate;
@bindable public plannedCompDate;
@bindable public duration;
@bindable public actualStartDate;
@bindable public actualStartDelta;
@bindable public commitDate;
@bindable public condition;
@bindable public conditionClass;
@bindable public conditionText;
@bindable public constraint;
@bindable public constraintDate;
@bindable public status;
@bindable public note;
@bindable public noteText;
@bindable public noteEntryDate;
@bindable public noteAvatarDownloadUrl;
@bindable public noteOwnerName;
@bindable public updateNoteText;
@bindable public actualCompletionDate;
constructor() {
// ... do constructor stuff
}
// ... other methods etc
}
卡commit.html
<!-- Do all sorts of stuff with the bound data, for example... -->
<template>
<!-- This example wouldn't really work, just demonstrating how I'm using the bound data -->
<article data-task-id="${ taskId }">
<ul repeat.bind="for example of task">
<li data-example-commit="example.commitDate">${example.condition}</li>
</ul>
</article>
</template>
也許我過於挑剔的,但如果感覺我應該能夠定義至少這種關係更緊湊的方式,特別是被定義的一長串綁定(本質)的兩倍。但我不確定我還能如何實現這一目標,並且無法真正找到有關該主題/問題的更多信息。
這些屬性是否獨立地改變,或者它們總是一次性改變爲一個組? –
@AshleyGrant:如果我正確理解你的問題,他們會立即改變。上述綁定的目的主要是顯示。但是,顯示的重點是讓用戶獨立更改某些屬性並將其提交回API。 – DjH
如果它們全都改變,那麼你可以只綁定一個單獨的屬性,它是具有所有這些屬性的對象。然後當你需要改變所有的屬性,只需綁定一個全新的對象。 –