我有以下可观察到的数组:如何在knockout中绑定到可观察数组中的项目?
self.Profiles =ko.observableArray(ko.utils.arrayMap(initialData, function (profile) {
return {
StartDate : formatDateOnly(profile.StartDate),
EndDate : formatDateOnly(profile.EndDate),
ProfileID :profile.ID,
ProfileName : profile.Name,
ProjectName : profile.ProjectName,
ReadingListID : profile.ReadingListID,
ReadingListName : profile.ReadingListName
};
}));
我要绑定一个下拉列表配置文件,以显示配置文件名称,如果下拉变化的值,那么我想更新与新的相应的span元素值添加到选定的profileID。
<table id="readingListApplyToProfile" class="fullWidthTable">
<tr>
<td>
Profile:
</td>
<td>
<select id="cboProfile" name="cboProfile" data-bind="options: Profiles, optionsText: 'ProfileName', 'optionsCaption': 'Select profile...', optionsValue:'ProfileID'"></select>
</td>
</tr>
<tr>
<td>
End Date:
</td>
<td>
<span data-bind="'text':EndDate"></span>
</td>
</tr>
</table>
因为span元素不知道下拉值,所以任何人都可以帮助我。我完全迷失了。
也许它会工作到选择的值绑定到computedObservable是发生在一个简档,并输出正确的配置文件的摘要名称,然后跨越文本结合相同computedObservable – jonhopkins 2013-03-20 13:01:01
,可能会工作,但我不想做所有的属性相同的代码,林希望有人能给我一个更好的解决方案。谢谢 – Xerxes 2013-03-20 13:02:38
有道理。这是一个完整的猜测,因为我不擅长computedObservables,但是可以输出整个Profile对象,并绑定到跨度上的特定属性?像'data-bind =“text:getProfile.ProfileName”'或类似的东西? – jonhopkins 2013-03-20 13:11:37