所以,當頁面加載時,如果複選框先前已被選中,並且數據在數據庫中,那麼複選框應顯示爲在表單中被選中。目前他們沒有被檢查(沒有綁定到數據庫)。如何使用Aurelia和mutiselect checkboxlist UI爲數組提供數據綁定?
下面是HTML
<div class="multiselect" style="width:170px; margin-top:30px">
<div class="selectBox" click.delegate="showCheckboxes('causes')">
<select>
<option style="font-weight:normal">Cause(s) to support</option>
</select>
<div class="overSelect"></div>
</div>
<iron-dropdown id="causes" horizontal-align="right" vertical-align="top" style="margin-top:25px;">
<div class="dropdown-content" style="background-color:white;box-sizing: border-box; max-width: 270px; max-height: 362px;overflow:auto;border:1px #dadada solid">
<label repeat.for="cause of causes" for="cause" style="display:block;text-align:left;margin-left:5px;margin-right:5px">
<input type="checkbox" value.bind="cause" checked.bind="selectedCause" change.delegate="causePicked()"> ${cause}
</label>
</div>
</iron-dropdown>
</div>
這裏是JavaScript
causes = ['Christian', 'Environmental', 'Hunger', 'Animal Rights', 'Homeless', 'Veterans', 'Elderly', 'other'];
talents = ['music', 'athletics', 'childcare', 'mechanics', 'construction', 'computers', 'communication', 'chess playing', 'listening', 'other'];
works = ['hashbrown slinging', 'nail hammering', 'leaf removal', 'floor mopping', 'counseling', 'other'];
selectedCause = [];
selectedTalent = [];
selectedWork = [];
async activate() {
this.uid = this.app.auth.getTokenPayload().sub;
this.user = await this.app.appState.getUser(this.uid);
//this.app.appState.user;
this.role = this.user.userType;
this.causes.sort();
this.talents.sort();
this.works.sort();
if (this.user.userType === 'Charity'){
this.role = 'Charity Manager';
}
}
這裏來回購的鏈接和src代碼 https://github.com/WebJamApps/combined-front/blob/dev/src/dashboard-child-routes/user-account.html
https://github.com/WebJamApps/combined-front/blob/dev/src/dashboard-child-routes/user-account.js
任何建議都非常讚賞,感謝