0

How can I use durandal compose functionality to implement knockout template binding for a sortable, dragging, dropping array?

I am using @RP Niemeyer knockout-sortable plugin witch is using templates.

So far I have made it work by storing the templates in the index file, but I am looking to implement it in the view.

<div class="well droppingZone" data-bind="sortable: { template: 'fieldTmpl', data: fields, options: { update: onUpdate } }"></div>
4

1 回答 1

0

我认为您的意思是动态加载模板文件,如果是这样,请查看@RP 开发的 Ko External 模板以及它将与 ko 模板无缝集成。但是,当我将 ko external 与 durandal js 一起使用时遇到了一些问题(猜测问题出在注入器上),所以我将 ExternalTemplateSource.js #getTemplate 更改为使用 durandal 的 viewLocator

 getTemplate: function () {
            var self = this;
            //system.log('Loading template:' + self.templateId);
            viewLocater.locateView(self.templateId).then(function (element) {
                self.data("precompiled", null);
                var t = $(element).html();
                setTimeout(function () {
                        self.template(t);

                }, 500);
                self.loaded = true;
            });
于 2013-10-03T09:08:28.840 回答