0

I have a view model:

function ViewModel() {
    this.applications = ko.observableArray();
    this.templateView = ko.observable("application-grid");
    this.templateToUse = function () {
        return this.templateView();
    }.bind(this);
};
var viewModel = new ViewModel();
ko.applyBindings(viewModel);

I have a list that is binded to the viewModel

<ul data-bind="template: { name: templateToUse, foreach: applications }"></ul>

When the page loads, it firs selects the "application-grid" template id.

When i change it first time, viewModel.templateView('application-list');, the template changes.

Then, if i change it back, viewModel.templateView('application-grid');, the template doesn't change anymore.

I am doing something wrong?

4

1 回答 1

0

如果要使用淘汰赛模板,则可以在绑定中指定:

<ul data-bind="template: { name: templateToUse, foreach: applications, templateEngine: new ko.nativeTemplateEngine() }"></ul>

默认情况下,如果在页面上引用,knout 将使用 jquery 模板。您也可以使用其他模板,有关更多信息,请参阅文档

于 2013-07-11T10:03:42.940 回答