[英]unable to render partial html using knockoutout component
I have defined component like below 我已经定义了如下组件
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 } });
}
}
} }
Then in cshtml i registered component like 然后在cshtml中我注册了组件
AgeModule.My_Component.registerComponent();
and load partial view like 并加载局部视图
@Html.Partial("~/Areas/Views/Home/Partials/MyComponent.cshtml", Model)
Then in partial view "MyComponent.cshtml" 然后在局部视图“ MyComponent.cshtml”中
<script type="text/html" id="mycomponent-template">
<div> KSJSDSSSSSSSSSSSSSSSSSSSSSSSSSSSS</div>
</script>
and i call component like 我称组件为
<mycomponent params="age: ageobs"></mycomponent>
i dont get any sort of errors in console but my partial view is not rendering at all. 我在控制台中没有得到任何错误,但是我的局部视图根本没有渲染。 I dont know how to debug either.
我也不知道如何调试。 How to solve this?
如何解决呢?
Update 更新
This works when i am binding component 当我绑定组件时有效
<div data-bind="component: {name: 'mycomponent', params: {age:ageobs}}">
</div>
But doesnt work if u use component tag directly. 但是,如果您直接使用元件标记,则无法使用。
I believe the component name must match the id in your "MyComponent.cshtml", so try either changing the static componentName: string = 'mycomponent';
我相信组件名称必须与“ MyComponent.cshtml”中的ID匹配,因此请尝试更改
static componentName: string = 'mycomponent';
to be editshipment-typeOfGoods
or the id to be mycomponent-template
成为
editshipment-typeOfGoods
或ID成为mycomponent-template
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.