Giter Site home page Giter Site logo

数据作用域的疑问 about amis HOT 7 CLOSED

baidu avatar baidu commented on March 29, 2024
数据作用域的疑问

from amis.

Comments (7)

2betop avatar 2betop commented on March 29, 2024

调用amis渲染器入口函数,

render(schema, props, env)

注意第二个参数是下发到渲染的 props 里面的,如果你在这个时候下发数据,这里面的数据就是全局的了

render(schema, {
  data: {
    appInfo: xxx,
    userInfo: xxx, 
   acl: xxx //  你还可以注入功能方法,这样 visibleOn 里面都能些  acl.can('doXXX')
  }
})

from amis.

g770728y avatar g770728y commented on March 29, 2024
return render(schema, {
                location,
                theme,
                aaa: 555,       <====== ( 1 )
                bbb: 'test',    <====== ( 2 )
                type: 'axx',    <====== ( 3 )
                data: {eee:3},   <======  ( 4 )
                ui: {
                    isVisibleFun: () => true,   <===========  ( 5 )
                    isVisible: true                    <===========  ( 6 )
                }
            }, this.env);

schema中:

  1. 使用tpl打印 aaa , bbb , eee , 无法获取到aaa, bbb:
{
    type: 'page',
    body: {
      type: 'tpl',
      tpl: '${&|json|html}'     =======>   { eee: 3}
    },
}

aaa, bbb 因为不在data中, 如何取出?


  1. 使用form.formItem:
{
   type: form,
   controls: [
       ...
       disabledOn: "ui.isVisibleOn()" ,           <== 无效
       disabledOn: "ui.isVisible",                    <==  无效
       disabledOn: "() => ui.isVisibleOn()"    <== 无效
   ]  
}

求指教...

from amis.

2betop avatar 2betop commented on March 29, 2024

都要放在 data 里面才能取出

from amis.

g770728y avatar g770728y commented on March 29, 2024

这样的话, 感觉有两个潜在问题:
1 ) 各级data在合并时, 容易存在重名覆盖问题
2 ) 顶级data既有数据也有方法, 方法也将逐渐向下合并


请教一下:
为何没有考虑 data 在合并时, 带上自己的name减少冲突机会呢?

{  
     [ top_component_name ] : { x: 1, y: 2},
     [ parent1_component_name ] : {x: 2, z: 3},
     [ self_component_name ] : { x: 3, z: 4}
}

可能实际情况没这么多冲突机会, 纯好奇 :)

from amis.

2betop avatar 2betop commented on March 29, 2024

不会向下合并,每一层的 原型链指向上一层的数据

from amis.

g770728y avatar g770728y commented on March 29, 2024

原型链是技术实现手段, 但在 最终使用amis 的程序员看来, 这与合并没啥两样...
不过确实稍微注意一下, 普通的mis系统也不会有什么命名冲突吧

感谢您的耐心回复 👍

from amis.

2betop avatar 2betop commented on March 29, 2024

如果出现重名可以尝试 ${__super.xxxx}

from amis.

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.