当前位置 : 主页 > 网页制作 > Dojo >

dojo小例子(6)页面打开后,请求数据,把反馈数据回填页面

来源:互联网 收集:自由互联 发布时间:2021-06-15
require(["dojo/parser","dojo/domReady!"], function(parser){parser.parse();});require(["dijit/form/Form", "dijit/form/ValidationTextBox", "dijit/form/TextBox", "dijit/form/Select", "dijit/form/Button"]); require(["dojo/request/xhr","dojo/dom
require([
	"dojo/parser",
	"dojo/domReady!"
], function(parser){
	parser.parse();
});

require(["dijit/form/Form", "dijit/form/ValidationTextBox", "dijit/form/TextBox", "dijit/form/Select", "dijit/form/Button"]);
 require(["dojo/request/xhr","dojo/domReady!"], function(xhr){

		xhr.get("/dojo/rest/getCompany", { // 请求数据
		    handleAs: "json"
		  }).then(function(data){

			  dijit.byId('myForm').set('value',data); // 数据回填表单,数据中的字段名必须和表单元素name一致
			  
		  }, function(err){
			  alert("err:"+err);
		  });
});
	<div data-dojo-type="dijit/form/Form" id="myForm">
	    <table>
	       <tr>
	       		<td align="right">
					公司名称:
			 	</td>
				<td nowrap>
					<input name="companyName" data-dojo-type="dijit/form/TextBox" value="三元"/>
				</td>
			</tr>
			<tr>
				<td align="right">
					电话号码:
				</td>
				<td nowrap>
					<input name="phone" data-dojo-type="dijit/form/TextBox" />
				</td>
			</tr>
		</table>
	</div>

数据请求成功,并自动回填表单的前提:

1、数据中的字段名和表单元素name一一对应

2、页面中用到的dojo插件都要事先require进来,否则就会报错WARNING: Modules being Auto-Required: dijit/form/TextBox

TypeError: dijit.byId(...) is undefined
网友评论