本节目录:
- 一个例子
- API
- component生命周期
- 备注1:仅模板式的component
- 备注2:component虚拟绑定
- 备注3:传递标记到component绑定
- 内存管理
一个例子
First instance, without parameters
Second instance, passing parameters
UI源码:
<h4>First instance, without parameters</h4> <div data-bind=‘component: "message-editor"‘></div> <h4>Second instance, passing parameters</h4> <div data-bind=‘component: { name: "message-editor", params: { initialText: "Hello, world!" } }‘></div>
视图模型源码:
ko.components.register(‘message-editor‘, { viewModel: function(params) { this.text = ko.observable(params && params.initialText || ‘‘); }, template: ‘Message: <input data-bind="value: text" /> ‘ + ‘(length: <span data-bind="text: text().length"></span>)‘ }); ko.applyBindings();
下午继续更
时间: 2024-12-29 01:57:02