从Knockoutjs Docs我不明白这句话:
模板已经注入到这个元素中,但还没有绑定。
ko.components.register('my-component', {
viewModel: {
createViewModel: function(params, componentInfo) {
// - 'params' is an object whose key/value pairs are the parameters
// passed from the component binding or custom element
// - 'componentInfo.element' is the element the component is being
// injected into. When createViewModel is called, the template has
// already been injected into this element, but isn't yet bound.
// Return the desired view model instance, e.g.:
return new MyViewModel(params);
}
},
template: ...
});