JSON2Table实现
Power App 无法直接调用http访问网络,借助Automate实现,通过访问Automate流程,返回网络数据,在通过ParseJSON进行数据转换为JSON对象,通过Table函数之间转换为Table
-
定义Automate Flow
在Automate Flow 创建流程,流程名称为HttpGetData4Unhealthy,共三个节点,如下图所示。


-
在Power apps 使用Automate Flow
引入流程HttpGetData4Unhealthy

-
Load数据
在Screen添加组件:
a. Text Label,Text 内容为 Json字符串
b.Text Input ,Mode,为Multiline,Default:varJSONStr
c.Button ,Text :load data
d. OnSelect写入代码如下:
//清除数据
Set(varJSONStr,Blank());
//运行Automate Flow 访问http,返回数据
Set(varJSONStr,
HttpGetData4Unhealthy.Run().return);
//利用ParseJSON函数将json字符串转换为JSON对象
Set(varJSONObj,ParseJSON(varJSONStr));
//利用Table函数,将JSON对象的data属性转换为Table,此时可以在Gallery显示数据,但是显示的Text属性设置为 ThisItem.Value.rm_stk_index
Set(varTableObj,Table(varJSONObj.data));
//定义Collect 将Table的数据加载到Collect
ClearCollect(colTableRecords,
ForAll(varTableObj,
{
assignee:Text(Value.assignee),
assignee_email:Text(Value.assignee_email),
rm_stk_index:Text(Value.rm_stk_index),
category:Text(Value.category),
legal_unit:Text(Value.legal_unit),
channel_mrp:Text(Value.channel_mrp),
stk_qty:Value(Value.stk_qty),
stk_sc:Value(Value.stk_sc),
stock_type:Text(Value.stock_type),
task_type:Text(Value.task_type),
unhealthy_qty:Value(Value.unhealthy_qty),
unhealthy_sc:Value(Value.unhealthy_sc),
version:Text(Value.version),
wh_desc:Text(Value.wh_desc)
}
));
-
显示在Galley上
在Screen上组件
a. Text Label,Text 内容为 查询
b.Text Input ,Name:txtSearch, Hint Text:查询
c. Gallery,添加显示组件Text Label ,Text属性设置为:ThisItem.rm_stk_index,属性名称参照OnSelect代码 定义Collect
e.在Gallery 的Items 写入如下代码:
Search(colTableRecords,
txtSearch.Text,
rm_stk_index,
assignee,
assignee_email)
-
界面效果如下:

-
运行效果

浙公网安备 33010602011771号