在viewModel之前注册knockout组件的问题

时间:2015-12-05 23:03:05

标签: javascript html twitter-bootstrap knockout.js

我尝试注册我的登录模态淘汰赛组件,但顶级视图是在我的组件注册之前创建的。

我使用requireJs来组织我的js文件。

这是视图

        .section .text
        .type bcd2dpd_mul,@function
        .globl bcd2dpd_mul

        # convert BCD to DPD with multiplication tricks
        # input abcd efgh iklm in edi
        .align 8
bcd2dpd_mul:
        mov %edi,%eax           #   = 0000 abcd efgh iklm
        shl %al                 #   = 0000 abcd fghi klm0
        shr %eax                #   = 0000 0abc dfgh iklm
        test $0x880,%edi        # fast path for a = e = 0
        jnz 1f
        ret

        .align 8
1:      and $0x888,%edi         #   = 0000 a000 e000 i000
        imul $0x49,%edi         #   = 0ae0 aei0 ei00 i000
        mov %eax,%esi
        and $0x66,%esi          # q = 0000 0000 0fg0 0kl0
        shr $8,%edi             #   = 0000 0000 0ae0 aei0
        and $0xe,%edi           #   = 0000 0000 0000 aei0
        mov lookup-4(%rdi),%dx
        movzbl %dl,%edi
        imul %edi,%esi          # v = q * tab[u-2][0]
        and $0x397,%eax         # r = 0000 00bc d00h 0klm
        xor %esi,%eax           # w = r ^ v
        or %dh,%al              #   = w | tab[u-2][1]
        and $0x3ff,%eax         #   = 0000 00xx xxxx xxxx
        ret

        .size bcd2dpd_mul,.-bcd2dpd_mul

        .section .rodata
        .align 4
lookup:
        .byte 0x11
        .byte 0x0a
        .byte 0x00
        .byte 0x4e
        .byte 0x81
        .byte 0x0c
        .byte 0x08
        .byte 0x2e
        .byte 0x81
        .byte 0x0e
        .byte 0x00
        .byte 0x6e
        .size lookup,.-lookup

这是我注册的地方

<div data-bind='component: componentModal'></div> - 在其中,有:

require(['modals/login']);

然后在我的主要js文件中,我有:

require(['jquery', 'knockout', 'text!modals/login.html', 'bootstrap'], function ($, ko, htmlString) {

    ko.components.register('login-modal', {
        viewModel: function (params) {
            console.log(params);
            this.text = ko.observable(params && params.initialText || '');
        },
        template: htmlString
    });
});

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:0)

我无法理解这一行:

self.componentModal = ko.observable('login-modal');

使用字符串'login-modal'创建一个observable什么都不做。它只是一个带有字符串登录模式的可观察对象。它并不神奇地包含你的模态组件。

您的html需要自定义<login-modal></login-modal>个html元素,甚至<div data-bind="component: {name: 'login-modal', params: {your: params}"></div>才能运行

您的&lt; script&gt;中的requirejs代码标签是错误的。我认为应该是:

require(['main', 'modals/login', 'knockout'], function(main, login, ko) {
// ... your code here
});