How to get the component's viewmodel from component's node in KnockoutJS

cryss

I have a component named 'my-component':

ko.components.register('my-component', { 

    viewModel: function() {      
        return { title: 'title' };     
    },

    template: '<div>x</div>'

});

I'm using this component in the view like that:

<my-component params=""></my-component>

Is there any way to get the component's view-model related to this HTML node? ko.dataFor doesn't work:

ko.dataFor($('my-component').get(0)) // it doesn't return component's view model

Any thoughts?

haim770

Try this:

ko.dataFor($('my-component').get(0).firstChild);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to get a react component's size (height/width) before render?

From Java

How to style child components from parent component's CSS file?

From Java

How to access the functional component's name from a React hook?

From Dev

How to get the AjaxRequestTarget inside Wicket's onBeforeRender() method of a component?

From Dev

Modifying a component's state from another component

From Dev

How can I get the "Edit Component's Name" window to show when I place a component?

From Dev

In ZK, change a component's property from other ViewModel

From Dev

How to load a KnockoutJS component programmatically

From Dev

Get Ember component's name

From Dev

How can I get a component's position on screen (screen coordinates)

From Dev

Showing a component only after the data for it's viewmodel has loaded

From Dev

KnockoutJS - binding child component's click event in parent's markup

From Dev

Get CSS property values from a component's "style" prop

From Dev

How to get component from component name in codenameone?

From Dev

How to set a Component's property value from inside a FileReader event

From Dev

How do you get the component's current native element?

From Dev

How to decouple a Component from it's own data fetching needs

From Dev

how to get trigger to affect triggering object's rigidbody component?

From Dev

How can I get the "Edit Component's Name" window to show when I place a component?

From Dev

In ZK, change a component's property from other ViewModel

From Dev

How to get a child component's contentchildren in Angular 2?

From Dev

How to get custom dll's working in a ssis script component?

From Dev

How do you get the component's current native element?

From Dev

How to set Ember component's internal state from parent component?

From Dev

How can I get a child component's watcher's updated value from parent component in Vue 2?

From Dev

How to access/get the value of the component's HTML id tag on React?

From Dev

How to reset a component's data

From Dev

Drupal 7: How do I retrieve a node's Content Type from within a component's prepocess function?

From Dev

How to call component's function from service?

Related Related

  1. 1

    How to get a react component's size (height/width) before render?

  2. 2

    How to style child components from parent component's CSS file?

  3. 3

    How to access the functional component's name from a React hook?

  4. 4

    How to get the AjaxRequestTarget inside Wicket's onBeforeRender() method of a component?

  5. 5

    Modifying a component's state from another component

  6. 6

    How can I get the "Edit Component's Name" window to show when I place a component?

  7. 7

    In ZK, change a component's property from other ViewModel

  8. 8

    How to load a KnockoutJS component programmatically

  9. 9

    Get Ember component's name

  10. 10

    How can I get a component's position on screen (screen coordinates)

  11. 11

    Showing a component only after the data for it's viewmodel has loaded

  12. 12

    KnockoutJS - binding child component's click event in parent's markup

  13. 13

    Get CSS property values from a component's "style" prop

  14. 14

    How to get component from component name in codenameone?

  15. 15

    How to set a Component's property value from inside a FileReader event

  16. 16

    How do you get the component's current native element?

  17. 17

    How to decouple a Component from it's own data fetching needs

  18. 18

    how to get trigger to affect triggering object's rigidbody component?

  19. 19

    How can I get the "Edit Component's Name" window to show when I place a component?

  20. 20

    In ZK, change a component's property from other ViewModel

  21. 21

    How to get a child component's contentchildren in Angular 2?

  22. 22

    How to get custom dll's working in a ssis script component?

  23. 23

    How do you get the component's current native element?

  24. 24

    How to set Ember component's internal state from parent component?

  25. 25

    How can I get a child component's watcher's updated value from parent component in Vue 2?

  26. 26

    How to access/get the value of the component's HTML id tag on React?

  27. 27

    How to reset a component's data

  28. 28

    Drupal 7: How do I retrieve a node's Content Type from within a component's prepocess function?

  29. 29

    How to call component's function from service?

HotTag

Archive