amis icon indicating copy to clipboard operation
amis copied to clipboard

card 展示 json 不知道怎么取值

Open faceair opened this issue 6 years ago • 9 comments

实现场景:

我期望使用 crud 展示 card 列表,每个 card 中使用 json 组件展示

存在的问题:

返回的数据在 items 数组中,不知道怎么将每个 item 全部赋值给 json 组件

当前方案:

{
    type: 'crud',
    filter: {
        title: '条件搜索',
        submitText: false,
        wrapWithPanel: false,
        controls: [
        {
            type: 'select',
            name: 'selector.component',
            label: '组件',
            source: '/api/amis/options/components',
            required: true
        },
        {
            type: 'text',
            name: 'selector.search',
            addOn: {
            label: '搜索',
            type: 'submit'
            },
            trimContents: true,
            required: true
        }
        ]
    },
    api: '/api/amis/resources?component=${selector.component}&search=${selector.search}',
    mode: 'cards',
    card: {
        body: {
            type: 'json',
            value: '${.}'
        }
    }
}

faceair avatar Aug 20 '20 05:08 faceair

type: 'json'同级加name: 'xxx',xxx为获取变量key值

文档里也有,https://baidu.gitee.io/amis/docs/components/cards#%E5%9F%BA%E6%9C%AC%E7%94%A8%E6%B3%95

image

RickCole21 avatar Aug 20 '20 07:08 RickCole21

可以在不加 key 包一层的情况下直接引用整个 item 吗?

faceair avatar Aug 20 '20 07:08 faceair

试试name:'$$'

RickCole21 avatar Aug 20 '20 08:08 RickCole21

{
    type: 'crud',
    syncLocation: false,
    headerToolbar: [],
    api: '/api/amis/resources?component=${selector.component}&search=${selector.search}',
    mode: 'cards',
    columnsCount: 2,
    card: {
        body: {
            type: 'json',
            value: '$$'
        }
    }
}

我修改的是 value,尝试过 $$ 和 ${$$} 都不能正常展示

faceair avatar Aug 20 '20 08:08 faceair

我让你设置name,你设置的是啥

RickCole21 avatar Aug 20 '20 08:08 RickCole21

非常感谢,有用! 之前是没太理解为什么要设置 name...

faceair avatar Aug 20 '20 08:08 faceair

之前是没太理解为什么要设置 name...

value是设置固定值,name一般是设置key来映射变量值的,功能不太一样

RickCole21 avatar Aug 20 '20 08:08 RickCole21

不过似乎多带了 "__super" 的属性,不知道有没有办法去掉 image

faceair avatar Aug 20 '20 08:08 faceair

后来换 json-view 的实现了,如果还有问题再报吧

nwind avatar Sep 23 '21 12:09 nwind