سؤال

I am using jQuery.tmpl and Knockout. Inside jQuery tmpl template I am using Knockout binding as follows:

<div data-bind="template: { name: 'field-String'}"></div>

I need to have dynamic template name. How can I achieve this?

I tried with no luck:

<div data-bind="template: { name: 'field-${Type}'}"></div>
هل كانت مفيدة؟

المحلول

You don't need the jQuery.tmpl syntax here, you can just use plain string concatenation to build your template name:

<div data-bind="template: { name: 'field-' + Type }"></div>

Note: if your Type is an ko.observable you need to write: name: 'field-' + Type()

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top