Can I pass a variable in a template binding?

前端 未结 4 676
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-15 10:45

I know this isn\'t a good method to use long term, but for troubleshooting, is there any way I can pass a simple string while binding a template and then access it as a variable

4条回答
  •  耶瑟儿~
    2021-02-15 10:58

    You can pass arbitrary data to a template, while maintaining the currently applied viemodel, by supplying a composition to the data parameter of the binding.

    You could for example wrap the template content in a with binding, bound to the composed $data property, creating a new binding context. This way, the currently applied bindings don't need to be updated.

    ko.applyBindings({
      fruits: ['banana', 'orange']
    });
    
    
    

提交回复
热议问题