[英]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.