百度amis平台经验分享(2)

1. amis里面的脚本如何调试? 可以在script里面加入debugger语句。

"actionType": "custom" ,script里面加入debugger;语句,可以在控制台查看context和event的信息

"onEvent": {
			 "confirm": {
				 "actions": [
					         {
								 "actionType": "custom",
								 "script":
									  "debugger;" +
									  "var form1 = event.context.scoped.getComponentById('formadd').getData();" +
												"event.context.scoped.getComponentById('formtable').getData().formadd=form1;"+
												"event.context.scoped.getComponentById('formtable').submit();"
										}
									]
								}
							}

2. 会使用amisScoped.getComponentById('xx'),amisScoped.getComponentByName('xx')获取实例的值。 以上用在多表单提交上比较有用(多个form合并提交)

也可以使用event.context.scoped.getComponentById("xxx");

3. onClick: (e, props) => {}的使用。

{
									"label": "提交表单",
									"actionType": "confirm",
									"primary": true,
									"type": "button",
									onClick: (e, props) => {
										console.log('消息通知',e,props);
										//console.log("${__rendererData|json}")
										//props.formStore.setValues({name: 'amis'});
									}
								}

 

 

4. amsi的组件会转成react,特别是body,其实就是组件的内容,或者说body里面的内容就是组件的子组件

5. type:tpl ,tpl:`这里可以写类似于JSP一样的脚本`

        { 'type': 'tpl',  'name': 'fileIds', 'label': '培训计划附件'  , "tpl": `
          <%
            console.log(data.fileIds); 
            if (data.fileIds) { 
            var urlArray = data.fileIds.split(',');
            for (var i = 0; i < urlArray.length; i++) { %>
              <a href="<%= urlArray[i] %>" target="_blank"><%= urlArray[i].split('/').pop() %></a><br/>
            <% }
          } %>
          `},

 

 

6. data属性很重要,在很多地方都能用到,例如上面的这个例子 5,就用到了data里面的数据。

7. 总体结构要清楚,type,body这样的无限递归,

8. 官方文档也不是所有都有,还需要GPT来协助加上搜索引擎,还有自己的debug经验,不是所有答案都能网上找到现成的,需要自己去挖掘。

9. 如果请求的数据不符合要求,可以修改,同理,接收的数据不符合要求,也可以修改。可以看看官方文档。 

"requestAdaptor": function (data, ctx) {
	console.log("-------------",data,ctx);
	//不需要返回,直接改data就可以
}
"adaptor": function (payload, response) {
	console.log("-------------",payload,response);
	 return payload;
}
"requestAdaptor": function (data, ctx) {
							// 这里打印出原始的 data 结构,不需要return
							console.log("原始 data 数据:",data);
						}

"adaptor": function (payload, response) {
					 //需要返回,这里是对结果的拦截,可以修改结果
					return payload;
	 }

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值