gpt4 book ai didi

daml - 向导航器添加按钮以进行选择

转载 作者:行者123 更新时间:2023-12-04 11:01:36 26 4
gpt4 key购买 nike

导航器包含一个功能,用户可以在其中定义自己的表 View ,请参阅 DAML docs for Navigator .

是否可以创建一个 View ,其中一列呈现一个按钮,单击时立即执行选择?

最佳答案

是的,这是可能的。自定义 View 允许您渲染任意 React 组件,因此让我们创建一个来进行选择。

首先,从一个工作 frontend-config.js 开始文件。 DAML quickstart project包含一个。

然后,确保至少在文件顶部导入以下符号:

import React from 'react';
import { Button, DamlLfValue, withExercise } from '@da/ui-core';

然后,定义以下顶级值(例如,正下方 export const version={...} ):


// Create a React component to render a button that exercises a choice on click.
const ExerciseChoiceButtonBase = (props) => (
<Button
onClick={(e) => {
props.exercise(props.contractId, props.choiceName, props.choiceArgument);
e.stopPropagation();
}}
>
{props.title}
</Button>
)
ExerciseChoiceButtonBase.displayName = 'ExerciseChoiceButtonBase';

// Inject the `exercise` property to the props of the wrapped component.
// The value of that property is a convenience function to send a
// network request to exercise a choice.
const ExerciseChoiceButton = withExercise()(ExerciseChoiceButtonBase)
ExerciseChoiceButton.displayName = 'ExerciseChoiceButton';

最后,在表格单元格定义中使用以下代码:

{
key: "id",
title: "Action",
createCell: ({rowData}) => {
// Render our new component.
// The contract ID and choice argument are computed from the current contract row.
return ({
type: "react",
value: <ExerciseChoiceButton
title='Transfer to issuer'
contractId={rowData.id}
choiceArgument={
DamlLfValue.record(undefined, [
{label: 'newOwner', value: DamlLfValue.party(DamlLfValue.toJSON(rowData.argument).issuer)}
])
}
choiceName='Iou_Transfer'
/>
});
},
sortable: true,
width: 80,
weight: 3,
alignment: "left"
}

另一种选择是创建一个 React 组件,其中 onClick处理程序使用 fetch() 发送 REST API 请求.在通过 Navigator UI 进行选择时检查网络流量,以找出请求的格式。

关于daml - 向导航器添加按钮以进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58767454/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com