Code Monkey home page Code Monkey logo

Comments (8)

louisscrew avatar louisscrew commented on May 6, 2024

目前官网提到的方法,都是通过最外层的父组件修改子组件的内容,通过this.sub.option即可。可是反过来,如果由于子组件的内容修改了,需要修改父组件或者兄弟组件的时候如何实现?knockout就提供了$root或者$parent的方式来更改其内容。

from omi.

dntzhang avatar dntzhang commented on May 6, 2024

@louisscrew
两种方式:
1.option里注册callback,callback会在子组件里执行。callback想干嘛就干嘛
2. 子组件里使用代码: this._nuclearParent.option.title = "abc";

推荐第一种,这种组件耦合度低。

from omi.

louisscrew avatar louisscrew commented on May 6, 2024

1.option里注册callback,callback会在子组件里执行。callback想干嘛就干嘛

请问这个callback,如何在option注册?能否给出一个demo,谢谢。

from omi.

louisscrew avatar louisscrew commented on May 6, 2024

@kmdjs

from omi.

dntzhang avatar dntzhang commented on May 6, 2024
this.childrenOptions = [
    {

    },
    {
        aa: xx,
        onClick: function () {
        },
        xxxHandler:function(){
            
        }
    }]

from omi.

louisscrew avatar louisscrew commented on May 6, 2024
  1. 子组件里使用代码: this._nuclearParent.option.title = "abc";

在子组件中没有获取到_nuclearParent这个对象啊,这个对象是undefined

from omi.

louisscrew avatar louisscrew commented on May 6, 2024

@kmdjs

from omi.

dntzhang avatar dntzhang commented on May 6, 2024

@louisscrew
使用nuclearParent,没有下划线。注意:0.5.2版本。
非常感谢。

from omi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.