我用几个控件构建了dhtmlxForm,其中之一是容器内的dhtmlxGrid。
我需要使用dhtmlxConnector render_array加载表单数据,但不知道执行此操作的最佳方法。
var myForm, myGrid;
var formData = [{type: "settings", position: "label-left", inputWidth: 150, labelWidth: 90},{type: "block", name: "buttonBlock", width: 500, list: [{type: "button", name: "btn1", value: "Patrick"},{type: "newcolumn", offsetLeft: 20},{type: "button", name: "btn2", value: "Edgar"},{type: "newcolumn", offsetLeft: 20},{type: "button", name: "btn3", value: "Renee"}]},{type: "block", width: 500, list: [{type: "input", name: "name", label: "Name"},{type: "input", name: "email", label: "E-mail"},{type: "input", name: "age", label: "Age", width: 70},{type: "select", name: "sex", label: "Sex", width: 70, options:[{text: "Male", value: "m"},{text: "Female", value: "f"}]},{type: "container", name: "userList", label: "Ordered items", inputWidth: 330, inputHeight: 200},{type: "hidden", name: "grid"}]}];
// server script name will loaded in “hidden” item with form data
var inProgress = false;
function doOnLoad() {
myForm = new dhtmlXForm("myForm", formData);
myForm.attachEvent("onButtonClick", function(name){
if (name.match(/^btn\d$/) != null && inProgress == false) {
updateForm(name.replace(/btn/,""));
}
});
myGrid = new dhtmlXGridObject(myForm.getContainer("userList"));
myGrid.setSkin("dhx_skyblue");
myGrid.setImagePath("codebase/imgs/");
// 1st load
updateForm(1);
}
function updateForm(index) {
//what is the best way to do it?
}
最佳答案
似乎正是您需要的方式:
function updateForm(index) {
inProgress = true;
myForm.load("xml/user"+index+".xml", function(){
// reload grid here
myGrid.clearAll();
myGrid.loadXML("xml/"+myForm.getItemValue("grid"), function(){
inProgress = false;
});
});
}