繁体   English   中英

无法使用淘汰赛组件呈现部分html

[英]unable to render partial html using knockoutout component

我已经定义了如下组件

module AgeModule {

export class My_Component {
    static componentName: string = 'mycomponent';
    static templateName: string = My_Component.componentName + '-template'; 
    myObs: KnockoutObservable<any>;

    constructor(params) {

        this.myObs = params && params.myObs;

    }
    static registerComponent = () => {
        ko.components.register(My_Component.componentName, { viewModel: My_Component, template: { element: My_Component.templateName } });
    }
}

}

然后在cshtml中我注册了组件

  AgeModule.My_Component.registerComponent();

并加载局部视图

  @Html.Partial("~/Areas/Views/Home/Partials/MyComponent.cshtml", Model)

然后在局部视图“ MyComponent.cshtml”中

<script type="text/html" id="mycomponent-template">
   <div> KSJSDSSSSSSSSSSSSSSSSSSSSSSSSSSSS</div>

 </script>

我称组件为

<mycomponent params="age: ageobs"></mycomponent>

我在控制台中没有得到任何错误,但是我的局部视图根本没有渲染。 我也不知道如何调试。 如何解决呢?

更新

当我绑定组件时有效

<div data-bind="component: {name: 'mycomponent', params: {age:ageobs}}">


</div>

但是,如果您直接使用元件标记,则无法使用。

我相信组件名称必须与“ MyComponent.cshtml”中的ID匹配,因此请尝试更改static componentName: string = 'mycomponent'; 成为editshipment-typeOfGoods或ID成为mycomponent-template

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM