首页 > 代码库 > 一个比较变态的js传值,Query的bind、ajax闭包、上下文传值

一个比较变态的js传值,Query的bind、ajax闭包、上下文传值

var getIDNameList = function (list, selected, text, btn, actionUrl, defaultKey, deleteKey, keyName, valueName, callBackFuc) {    btn.bind("click keyup", { sText: text }, function (e) {        $.ajax({            url: actionUrl,            contentType: "application/json",            type: "GET",            success: $.proxy(function (data) {                var comparStr = this.val();                for (var i = 0; i < data.length; i++) {                                        if (data[i][valueNameStr].indexOf(comparStr) == -1)                        continue;                }            }, e.data.sText)        });    });}//调用var i=1;getIDNameList(             $(#List + i),             $(#S + i),             $(#searchText + i),             $(#searchBtn + i),             "../scripts/A04/A0410.json",             null, null, "Key", "Value", function (obj) {                              });             //HTML<div class="btn-group">    <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false">        <span data-bind="attr:{id:‘S‘+$index()}">请选择</span><span class="caret"></span>    </button>    <ul class="dropdown-menu" role="menu" data-bind="attr:{id:‘List‘+$index()}" ></ul>    <div class="input-group">        <input type="text" class="form-control" data-bind="attr:{id:‘searchText‘+$index()}" placeholder="专业类别名称">        <span class="input-group-btn">            <button class="btn btn-primary" id="c2-searchBtn"  data-bind="attr:{id:‘searchBtn‘+$index()}"  type="button">                搜索            </button>        </span>    </div></div>// A0410.json[{    "Key": "1",    "Value": "哲学"},{    "Key": "101",    "Value": "哲学类"},{    "Key": "10101",    "Value": "哲学"},{    "Key": "10102",    "Value": "逻辑学"}]

 

一个比较变态的js传值,Query的bind、ajax闭包、上下文传值