Leaf 关于同行结构的使用
第一步:
创建两个grid组件用于存放数据
代码如下:
<a:form column="2" width="600" id="dataForm">
//注:bintarget 的作用是绑定数据源
//查找国家信息
<a:grid id="query_country" bindTarget="query_country_name" height="400" navBar="true" width="400">
<a:toolBar>
<a:button type="add"/>
<a:button type="delete"/>
<a:button type="clear"/>
<a:button type="save"/>
<a:button text="保存数据" click="save_data"/>
</a:toolBar>
<a:columns>
<a:column name="description" prompt="国家名" editor="txt_editor" width="200"/>
</a:columns>
<a:editors>
<a:textField id="txt_editor"/>
</a:editors>
</a:grid>
//查找省份信息
<a:grid bindTarget="query_province" height="400" id="province_info" navBar="true" width="200">
<a:toolBar>
<a:button type="add"/>
<a:button type="delete"/>
<a:button type="clear"/>
</a:toolBar>
<a:columns>
<a:column name="description" prompt="省名称" editor="txt_editor_or" width="150"/>
</a:columns>
<a:editors>
<a:textField id="txt_editor_or"/>
</a:editors>
</a:grid>
</a:form>
接下来书写dataSet 的 code;
<a:dataSet id="query_country_name" fetchAll="false" model="course1907.DEMO1.cus_201907_demo2_val"
autoCount="true" autoQuery="true" autoPageSize="true" selectable="true"
submitUrl="${/request/@context_path}/modules/course1907/DEMO1/cus_201907_demo_update.lsc">
<a:fields>
<a:field name="description">
</a:field>
<a:field name="country_id"></a:field>
</a:fields>
<a:events>
<a:event name="indexchange" handler="indexChangeFunction"/>
</a:events>
</a:dataSet>
其中,必须要注意的是 model 对应的文件course1907.DEMO1.cus_201907_demo2_val
这里面必须要对主键字段给出定义。 submitUrl为自己编写的一个isc文件,isc 需要经过页面注册和分配才能够使用。
sourcepath="/parameter" 为传递的json 格式的数据, <p:switch test="@current_parameter/@_status">
就是取当前数据的状态, <p:case value="update">
对到底是进行insert,update还是delete 进行判断,进入到相应的循环体内,
<a:model-update model="course1907.DEMO1.cus_201907_demo2_val"/>
<a:model-batch-update model="course1907.DEMO1.cus_201907_demo1_val" sourcepath="@current_parameter/country_ds"/> 对json 数据进行级联取值判断。
然后看字表的数据源
<a:dataSet id="query_province" fetchAll="true" bindName="country_ds" bindTarget="query_country_name"
model="course1907.DEMO1.cus_201907_demo1_val" autoPageSize="true" selectable="true"
queryUrl="${/request/@context_path}/autocrud/course1907.DEMO1.cus_201907_demo1_val/query">
<a:fields>
<a:field name="province_id">
</a:field>
<a:field name="description"/>
</a:fields>
</a:dataSet>
bindName=“country_ds” 为json 数据取值时的路径,bindTarget="query_country_name"为父表的id ,bindTarget="query_country_name为字表自己的lwm文件,里面对主键和外键进行声明。文件如下
<?xml version="1.0" encoding="UTF-8"?>
<ns1:model xmlns:ns2="leaf.database.local.oracle" xmlns:ns1="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="fp" baseTable="fnd_province">
<ns1:fields>
<ns1:field name="country_id" databaseType="BIGINT" datatype="java.lang.Long" insertExpression="${../../@country_id}" updateExpression="${../../@country_id}"/>
<ns1:field name="province_id" databaseType="BIGINT" datatype="java.lang.Long" physicalName="PROVINCE_ID"/>
<ns1:field name="description" databaseType="VARCHAR" datatype="java.lang.String" displayWidth="250" forDisplay="true" forQuery="true" physicalName="DESCRIPTION" prompt="HLS.DESCRIPTION"/>
</ns1:fields>
<ns1:primary-key>
<ns1:pk-field name="province_id"/>
</ns1:primary-key>
<ns1:query-fields>
<ns1:query-field field="country_id" queryOperator="="/>
</ns1:query-fields>
<ns1:features>
<f:multi-language-storage/>
<ns2:sequence-pk/>
<f:standard-who/>
</ns1:features>
<ns1:ref-fields/>
</ns1:model>
要注意的是主键必须加上insertExpression="${../../@country_id}" updateExpression="${../../@country_id}"
,目的是取到相应的id值,能够进行插入和更新操作。
定义字表的主键,和父表的主键(用于查询字表)。
最终,leaf 的同行结构的操作就完成啦~~~~~~~~