是否可以从js文件调用组件并将其附加到正文?例如,这是我的代码:
define(['jquery', 'knockout'], function ($, ko) {
ko.components.register('page1', {
require: 'App/Controllers/page1'
})
ko.applyBindings();
$('#body').html('<page1></page1>');
})
但是组件没有加载。如果tag在常规html中,它可以正常工作
答案 0 :(得分:0)
Two ways:
First add the html element, then apply binding.
$('#body').html('<page1></page1>');
ko.applyBindings();
Add the html element and then apply bindings to it as a descendent.
ko.applyBindingsToDescendants(viewModel,element);