2012-11-16 69 views
0

如何动态地设置KO模板名称时dropn选单中选择价值变动..Dynamcially设置模板名称

我试过,但我没有得到正确的模板。

<select data-bind="options: Attributes, optionsText: 'AttributeName', optionsValue: 'Id', optionsCaption: 'Select Attribute...',value :SelectedAttribute"></select> 
<div data-bind="template: { name: SelectedAttribute }"></div> 
+0

你可以请张贴一些代码到目前为止,并演示你的问题? – nemesv

回答

0

你应该确保SelectedAttribute不为空,并添加()可观察得到它的价值:

<!-- ko if: SelectedAttribute --> 
<div data-bind="template: { name: SelectedAttribute() }"></div> 
<!-- /ko --> 

这里是工作提琴:http://jsfiddle.net/vyshniakov/HUExe/

在我看来,那template结合不会打开传递给名称选项的值。