摘要:
在修改基础信息的时候,通常会遇到需要修改值为选择值的时候,这时候,数据库存的一般是value,而不是显示的text值,但页面显示的时候如果显示成数字型的值,通常会给人不够直观的感觉。因此,要求页面在加载的时候,根据value,初始化combobox的选择值。
疑难点:
表单配置值:
{ display: Dictionary.mrl.mrl_class_gid, newline: true, name: "pid", type: "select", comboboxName: "pid_com", options: { textField: 'name', valueField: 'sysno', data: data, onSelected: f_select } }
虽然ligerComboBox({})中有value的方法和属性,但因为无法通过选择器定位到该combobox,所以无法实现初始化值。
尝试1:直接在options中添加value属性。
{ display: Dictionary.mrl.mrl_class_gid, newline: true, name: "pid", type: "select", comboboxName: "pid", options: { textField: 'name', valueField: 'sysno', data: data, value: "5831531369ef4ec5bfafda73a0ed23c7" } }
结果:失败,并为加载成功
尝试2:在formload以后,单独调用ligerCombobox()方法。
api.loadForm($("#form1"), {
data: fdata
}); setTimeout(function () {
$("#pid_com").ligerComboBox({
data: data,onSelected: f_select,value:fdata.pid
});
}, 100);
结果:失败。应该是$选择器的问题。
利用selector将combobox内容打出:
{
"context": {
"location": {
"hash": "",
"search": "?type=modify&sysno=9f8cecaee89a49fdb02f7465f90ea418",
"pathname": "/WebFiles/Material/Mrl_Class_Item.html",
"port": "26003",
"hostname": "localhost",
"host": "localhost:26003",
"protocol": "http:",
"origin": "http://localhost:26003",
"href": "http://localhost:26003/WebFiles/Material/Mrl_Class_Item.html?type=modify&sysno=9f8cecaee89a49fdb02f7465f90ea418",
"ancestorOrigins": {
"0": "http://localhost:26003",
"1": "http://localhost:26003"
}
},
"jQuery19009037283264977614": 1
},
"selector": "#pid_com" }
可以看到,选择器是没有问题的,$("#pid_com"),那通过.val()赋值,不知道会不会成功呢
{"0":{},"length":1,"context":{"location":{"hash":"","search":"?type=modify&sysno=9f8cecaee89a49fdb02f7465f90ea418","pathname":"/WebFiles/Material/Mrl_Class_Item.html","port":"26003","hostname":"localhost","host":"localhost:26003","protocol":"http:","origin":"http://localhost:26003","href":"http://localhost:26003/WebFiles/Material/Mrl_Class_Item.html?type=modify&sysno=9f8cecaee89a49fdb02f7465f90ea418","ancestorOrigins":{"0":"http://localhost:26003","1":"http://localhost:26003"}},"jQuery1900602295770961512":1},"selector":"#pid"}
确定
最终答案:
应该是选择器用错,应该用name的方式来获取控件。 $("[name=pid_com]").val(fdata.pname);