XForms/带原点的插入
外观
< XForms
您希望将新值插入模型实例中,并指定在何处查找插入的初始值。
您可以向 insert 语句添加 origin 属性,以告诉 XForms 在何处获取插入的初始数据。这是优于执行多个 setvalues 的方法。insert 语法的格式如下
<xf:insert ev:event="DOMActivate"
nodeset="instance('persons')/Person"
at="last()" position="after"
origin="instance('init')/Person"/>
一个示例屏幕图像。许多人无法运行示例,因此这一点至关重要。
使用此格式
确保您使用许可证标记所有图像。如果您愿意,请使用“署名-相同方式共享 3.0” 创作共用。
确保在 svn 系统中将 mime 类型设置为 text/xml。
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xf="http://www.w3.org/2002/xforms">
<head>
<title>Insert with Origin</title>
<style type="text/css">
@namespace xf url("http://www.w3.org/2002/xforms");
body {font-family:Helvetica, sans-serif}
</style>
<xf:model>
<xf:instance xmlns="" id="persons">
<data>
<Person>
<PersonGivenName>John</PersonGivenName>
<PersonFamilyName>Doe</PersonFamilyName>
<PersonGenderCode>unknown</PersonGenderCode>
<XFormsAwareIndicator>false</XFormsAwareIndicator>
</Person>
<Person>
<PersonGivenName>Sue</PersonGivenName>
<PersonFamilyName>Smith</PersonFamilyName>
<PersonGenderCode>unknown</PersonGenderCode>
<XFormsAwareIndicator>false</XFormsAwareIndicator>
</Person>
</data>
</xf:instance>
<xf:bind nodeset="XFormsAwareIndicator" type="xs:boolean"/>
<!-- initial values for new Person records -->
<xf:instance xmlns="" id="init">
<data>
<Person>
<PersonGivenName></PersonGivenName>
<PersonFamilyName></PersonFamilyName>
<PersonGenderCode>unknown</PersonGenderCode>
<XFormsAwareIndicator>false</XFormsAwareIndicator>
</Person>
</data>
</xf:instance>
</xf:model>
</head>
<body>
<h3>Insert with Origin</h3>
<xf:repeat nodeset="Person" id="person-repeat">
<xf:input ref="PersonGivenName">
<xf:label>First Name: </xf:label>
</xf:input>
<xf:input ref="PersonFamilyName">
<xf:label>Family Name: </xf:label>
</xf:input>
<xf:select1 ref="PersonGenderCode">
<xf:label>Gender: </xf:label>
<xf:item>
<xf:label>Male</xf:label>
<xf:value>male</xf:value>
</xf:item>
<xf:item>
<xf:label>Female</xf:label>
<xf:value>female</xf:value>
</xf:item>
<xf:item>
<xf:label>Unknown</xf:label>
<xf:value>unknown</xf:value>
</xf:item>
</xf:select1>
<xf:input ref="XFormsAwareIndicator">
<xf:label>Indicator: </xf:label>
</xf:input>
</xf:repeat>
<xf:trigger>
<xf:label>Add</xf:label>
<xf:insert ev:event="DOMActivate" nodeset="instance('persons')/Person" at="last()" position="after"
origin="instance('init')/Person"/>
</xf:trigger>
</body>
</html>