[英]Aurelia/Typescript - How do I bind an object to a variable thru select tag
So, I have a static array of objects in JSON. 因此,我在JSON中有一个静态对象数组。 I've populated a select tag with those options successfully and set the value of each option of the select tag to the object id. 我已经使用这些选项成功填充了select标签,并将select标签的每个选项的值设置为对象ID。
tvs: any[] = [
{ "id": 1, "ip": "11.11.11.111", "port": "8080", "name": "tv 1" },
{ "id": 2, "ip": "11.11.11.111", "port": "8080", "name": "tv 2" },
{ "id": 3, "ip": "11.11.11.111", "port": "8080", "name": "tv 3" },
{ "id": 4, "ip": "11.11.11.111", "port": "8080", "name": "tv 4" },
{ "id": 5, "ip": "11.11.11.111", "port": "8080", "name": "tv 5" },
{ "id": 6, "ip": "11.11.11.111", "port": "8080", "name": "tv 6" }
];
and then in my html file: 然后在我的html文件中:
<div class="col-md-6 col-lg-6">
<label>Which tv do you want to alter?</label>
<select class="form-control">
<option repeat.for="tv of tvs" value="${tv.id}">${tv.name}</option>
</select>
</div>
That works great, however I want to add a dynamic div below this one and have it change and show information based on the selected object. 效果很好,但是我想在该分区下添加一个动态div并对其进行更改并根据所选对象显示信息。 For example, if the user selects tv 5 in the select tag, I want it to show the information for tv 5. How do I bind the selected object to something so that I can accomplish this? 例如,如果用户在select标签中选择了tv 5,我希望它显示有关tv 5的信息。如何将所选对象绑定到某物,以便可以完成此操作?
Aurelia provides model.bind
for use on option
elements inside a select
. Aurelia提供了model.bind
用于select
内的option
元素。 For your example something like this should work: 对于您的示例,这样的事情应该起作用:
<div class="col-md-6 col-lg-6">
<label>Which tv do you want to alter?</label>
<select class="form-control" value.bind="selectedTV">
<option repeat.for="tv of tvs" model.bind="tv">${tv.name}</option>
</select>
</div>
<div if.bind="selectedTV">
Info for TV ${selectedTV.name}:<br>
ip: ${selectedTV.ip}<br>
etc...
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.