durandal applybindings如何

时间:2013-12-16 23:09:29

标签: knockout.js durandal

Durandal很新,但已经使用淘汰赛一段时间了。我创建了一个js模块和一个包含knockout绑定的html页面,但是淘汰被忽略了(好像applybindings没有运行)。我在控制台中没有收到任何错误。

durandal会自动运行applybindings,还是我需要在Activate()中以某种方式执行此操作?

这是我的代码:

define(['plugins/http', 'durandal/app', 'knockout','plugins/dynamiccss'], function (http, app, ko,cssLoader) {

    var ctor = function () {
        this.compositionComplete = function () {
            cssLoader.loadCss("Content/css/tables.css");
        };
        this.deactivate = function () {
            cssLoader.removeModuleCss();
        }
        this.awards = ko.observableArray([]);
        this.activate = function () {
            var that = this;
            return $.ajax({
                url: 'Budget/GetAwards',
                type: 'POST',
                cache: false,
                context: this,
                data: ko.toJSON({Id:'1'}),
                contentType: 'application/json; charset=utf8',
                async: true,
                success: function (response) {
                    that.awards(response.Model);
                }
            });

        }

    };


    return ctor;
});

这是html:

<section>
    <h2 data-bind="html:displayName"></h2>

    <table class="input-cells">
        <thead><tr><th>Award Number</th><th>Pipeline Sector</th></tr></thead>
        <tbody data-bind="foreach:awards">
            <tr>
                <td><b data-bind="text:AwardNumber"></b></td>
                <td><select data-bind="options:['test1','test2','test3'],value:PipelineSectorId"></select></td>
            </tr>
        </tbody>
    </table>
</section>

这一切都表现得好像从未发生过applybindings。有关如何调试的建议吗?

谢谢!

0 个答案:

没有答案