DWRUtils DWREngine API使用方法


$("precloneNode1suf")  取得该对象;

DWRUtil.selectRange("selectRangeBasic", 5, 15) 选中selectRangeBasic文本框里面从第五个字符到第15个字符之间的字符.

DWRUtil._getSelection("selectRangeBasic") 得到selectRangeBasic文本框里选中的字符.

var arrayFive = [ 'One', 'Two', 'Three', 'Four', 'Five' ];
DWRUtil.addOptions('addOptionsBasic', arrayFive); 将数组添加到下拉菜单里面去;

DWRUtil.getValue('addOptionsBasic') 得到 addOptionsBasic 对象的值;
DWRUtil.getValue("precloneNode1Inner1suf", { textContent:true }); 后面加个参数,在 precloneNode1Inner1suf元素为"UL" 时,它返回了元素里面得值,也就是说去掉了HTML标签部分.

DWRUtil.getText('addOptionsBasic') 得到下拉框 addOptionsBasic 显示的文本;

var arrayObject = [
  { name:'One', value:'1' },
  { name:'Two', value:'2' },
  { name:'Three', value:'3' },
  { name:'Four', value:'4' },
  { name:'Five', value:'5' }
];
DWRUtil.addOptions('addOptionsObject1', arrayObject, "name"); 将数组添加到下拉菜单里面去;后面的参数是确定那个是给用户显示的文本,同时也是值;

DWRUtil.addOptions('addOptionsObject1', arrayObject, "name","value"); 同上,不过后面参数是: 3=文本;4=值;

var map = { one:1, two:2, three:3, four:4, five:5 };
DWRUtil.addOptions('addOptionsMap1', map);  同上, one 是值;1 是文本;
DWRUtil.addOptions('addOptionsMap1', map,true);  同上, 1 是值;one 是文本;

-------------------------------------------------------------------------------------
  <ul id="removeItems">
    <li>One</li><li>Two</li><li>Three</li><li>Four</li><li>Five</li>
  </ul>

如果是列表显示,如上;则上面所有方法和select 下拉框使用一样;
-------------------------------------------------------------------------------------
DWRUtil.cloneNode('cloneNode1', { idPrefix:'pre', idSuffix:'suf' });克隆一个节点,参数一为要克隆的节点的id,第二个参数是在克隆的节点id前面加pre,后面加suf.(注意:如果该节点有子节点的话,子节点的名字也一样加)

DWRUtil.addRows(id, array, cellfuncs, [options]);
原理:

for each member in array
  for each function in cellfuncs
    create cell from cellfunc(array[i])
循环数组,循环函数,建立单元调用函数;(顺序决定)

例如:
DWRUtil.addRows('addRowsBasic', arrayFive, [
    function(data) { return data; },
    function(data) { return data.toUpperCase(); },
    function(data) {
      var input = document.createElement("input");
      input.setAttribute("type", "button");
      input.setAttribute("value", "DOM Test");
      input.setAttribute("onclick", "alert('" + data + "');");
      return input;
    },
    function(data) { return "<input type='button' value='innerHTML Test' onclick='alert(\"" + data + "\");'>"; }
  ]);

高级部分:
第四个参数为对单元的高级操作,主要下面的两个方法;
function defaultRowCreator(options) {
  return document.createElement("tr");
};

function defaultCellCreator(options) {
  return document.createElement("td");
};

例子:
DWRUtil.addRows( "demo2",[ 'Africa', 'America', 'Asia', 'Australasia', 'Europe' ] , cellFuncs, {
  rowCreator:function(options) {
    var row = document.createElement("tr");
    var index = options.rowIndex * 50;
    row.style.color = "rgb(" + index + ",0,0)";
    return row;
  },
  cellCreator:function(options) {
    var td = document.createElement("td");
    var index = 255 - (options.rowIndex * 50);
    td.style.backgroundColor = "rgb(" + index + ",255,255)";
    td.style.fontWeight = "bold";
    return td;
  }
});

其中 options 参数的属性可用的为:(没试过,自己试试吧)

rowData: the element value from the array (the same for all cells in a row) 
rowIndex: the key (if map) or index (if array) from the collection 
rowNum: The row number counting from 0 in this section (so if you are using tbody,  it counts rows in the tbody and not the whole table) 
data: The 'computed' data value for the cell (cellCreators only) 
cellNum: The cell number that we are altering counting from 0 (cellCreators only) 


DWRUtil.setValues(); 批量设置值;
  var settings = {
    setValuesDiv:"setValuesDiv",
    setValuesSpan:"setValuesSpan",
    setValuesSelect:"two",
    setValuesText:"setValuesText",
    setValuesPassword:"AB",
    setValuesTextarea:"setValuesTextarea",
    setValuesButton1:"B1-Two",
    setValuesButton2:"B2-Two",
    setValuesRadio1:true,
    setValuesRadio2:false,
    setValuesRadio3:"one",
    setValuesRadio4:"two",
    setValuesCheckbox1:true,
    setValuesCheckbox2:false
  };
  DWRUtil.setValues(settings);

DWRUtil.getValues(empty);批量获取值;
  var empty = {
    setValuesDiv:null,
    setValuesSpan:null,
    setValuesSelect:null,
    setValuesText:null,
    setValuesPassword:null,
    setValuesTextarea:null,
    setValuesButton1:null,
    setValuesButton2:null,
    setValuesRadio1:null,
    setValuesRadio2:null,
    setValuesRadio3:null,
    setValuesRadio4:null,
    setValuesCheckbox1:null,
    setValuesCheckbox2:null
  };
  DWRUtil.getValues(empty);

  DWRUtil.useLoadingMessage("Ping");//类似gmail那个样子,在右上角显示加载"ping";可用自定样式,具体查询;http://getahead.ltd.uk/dwr/browser/util/useloadingmessage

  DWRUtil.toDescriptiveString("id",数字);弹出调试信息,数字为0,1,2.一级比一级高.

  DWRUtil.onReturn(event, submitFunction);一般在form表单里面,防止在文本框上按回车就提交表单.
例如:
<input type="text"
    onkeypress="DWRUtil.onReturn(event, submitFunction)"/>
<input type="button" onclick="submitFunction()"/>

 

 

DWREngine.beginBatch(); 开始缓存;

DWREngine.endBatch();提交缓存;

DWREngine.defaultMessageHandler(abc);默认的消息句柄;

DWREngine.setTextHtmlHandler;当接收到html时发生的事件;<没有期待到javascript时,不解其意>

DWREngine._httpSessionId; 会话id;

DWREngine._scriptSessionId; 当前页的id;

DWREngine.setErrorHandler(abc); 默认错误句柄;

DWREngine.setWarningHandler(abc);默认警告句柄;

DWREngine.setTimeout(0); 超时时间设置,默认是0;

DWREngine.setPreHook(abc);当dwr进行远程调用的之前被调用;

DWREngine.setPostHook(abc);当dwr进行远程调用的之后被调用;

//三种调用方法;
DWREngine.XMLHttpRequest = 1;
DWREngine.IFrame = 2;
DWREngine.ScriptTag = 3;

DWREngine.setMethod(<1 or 2 or 3>);设置调用远程的方法;

DWREngine.setVerb = function(<'GET' or 'POST'>);设置发送数据的方法;

DWREngine.setOrdered(<true or false>);设置xhr的请求按顺序执行.<官方强烈建议不要用这个,会变的很慢而且无法预测.>

DWREngine.setAsync (<true or false>);设置xhr的请求方法是否异步?默认是true;(官方文档中强调,尽量不要修改该属性,如果修改后不会再其他方法中起效.并且有些时候会使你的浏览器无响应变得倾向于中止的状态,如果你要使用建议也设置超时选项).


------------------------------------------------------------------
//以下未读懂,以后补充;
DWREngine.setPolling();已经废弃,由DWREngine.setReverseAjax()替代;

DWREngine.setReverseAjax = function(reverseAjax) {
  DWREngine._reverseAjax = reverseAjax;
  if (DWREngine._reverseAjax) {
    DWREngine._triggerNextPoll(0);
  }
};

DWREngine.setPollUsingComet = function(pollComet) {
  DWREngine._pollComet = pollComet;
};

DWREngine.setPollMethod(<1 or 2 or 3>);设置****的方法;

 

你可能感兴趣的:(JavaScript,浏览器,DWR,Gmail)