一个比较变态的js传值,Query的bindajax闭包上下文传值
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一个比较变态的js传值,Query的bindajax闭包上下文传值相关的知识,希望对你有一定的参考价值。
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的bindajax闭包上下文传值的主要内容,如果未能解决你的问题,请参考以下文章