标签:
1 ko.components.register( ‘component-name‘ , { 2 viewModel : something… , 3 template : something… 4 });
1 var shareViewModelInstance = {...}; 2 ko.components.register( ‘my-component‘ , { 3 viewModel : { instance : shareViewModelInstance }, 4 template : ... 5 });
1 ko.components.register(‘ my-component‘ , { 2 viewModel: { 3 createViewModel: function(params, componentInfo){ 4 return new MyViewModel( params ); 5 } 6 }, 7 template: ... 8 });
1 ko.components.register( 2 viewModel: { require: ‘some/module/name‘ }, 3 template: ... 4 )
1 define( [‘knockout‘], function(ko){ 2 function MyViewModel(){ 3 ... 4 } 5 return MyViewModel; 6 // return { instance: new MyViewModel()}; 7 //... 8 });
1 <template id=‘component-template‘> 2 <h1>...</h1> 3 </template>
1 ko.components.register(‘my-component‘,{ 2 template: {element: ‘component-template‘}, 3 viewModel: ... 4 });
template:{ require: ‘/some/template‘}
template:{ require: ‘text!path/file.html‘}
synchronous: true
默认为false,异步加载
标签:
原文地址:http://www.cnblogs.com/mansu/p/4444934.html