【发布时间】:2016-03-29 00:34:00
【问题描述】:
我有以下代码可用于显示模式:
app.html
<a click.delegate="setModal('person-information')">Test</a>
<modal>
<modal-header title.bind="'View Person'"></modal-header>
<modal-body content.bind="contentModal"></modal-body>
<modal-footer buttons.bind="['Cancel']"></modal-footer>
</modal>
app.js
setModal(modal) {
this.contentModal = modal;
$('.modal').modal();
}
person-information.html
<template>
<form role="form">
<div class="form-group">
<label for="fn">First Name</label>
<input type="text" value.bind="person.firstName" class="form-control" id="fn" placeholder="first name">
</div>
<div class="form-group">
<label for="ln">Last Name</label>
<input type="text" value.bind="person.lastName" class="form-control" id="ln" placeholder="last name">
</div>
</form>
</template>
person-information.js
import {bindable, inject} from 'aurelia-framework';
@inject(Element)
export class PersonInformation {
constructor() {
this.person = new Person();
}
}
class Person{
firstName = 'Patrick';
lastName = 'Bateman';
}
此代码可以很好地显示以下内容:
我无法弄清楚如何注入自己的数据来动态创建“Person”。
伪代码:
app.html
<a click.delegate="setModal('person-information', 'Tom', 'Hanks')">Test</a>
app.js
setModal(modal, firstname, lastname) {
this.contentModal = modal;
this.contentModal.Person.firstName = firstname;
this.contentModal.Person.lastName = lastname;
$('.modal').modal();
}
有人有这方面的经验吗?
【问题讨论】:
-
我在这里没有看到任何不起作用的东西,
setModal没有得到你的正确值还是什么? -
@PWKad 在调用 setModal 函数时,我在 js 控制台中得到以下错误:
Uncaught TypeError: Cannot set property 'firstName' of undefined如果我尝试这样做:this.contentModal.person = new Person();我得到:Uncaught TypeError: Cannot assign to read only property 'person' of person-information
标签: javascript jquery html aurelia