将一个变量传递给另一个函数(jeasui)
Passing a variable into an other function ( jeasyui )
你好,我一直在拼命地尝试在函数之间传递变量,我尝试过一些解决方案,但它们都不起作用——也许我做错了。我不知道如何解决这个问题,这对你们中的一些人来说可能是微不足道的,期待着帮助。
它是如何工作的:输入无线电应该在url中添加一个参数(queryParams-根据文档,所有参数都应该可以),我称之为显示指定数据的附加过滤器。单击某个单选脚本时,该脚本将获取值,并应将其附加到queryParams。
如果您有更多问题,请毫不犹豫地提出
<div class="adv_filter">
<li>
<input type="radio" name="letter_type" data-custom="Radio1" value="0">Radio1</li>
<li>
<input type="radio" name="letter_type" data-custom="Radio2" value="1" checked="checked">Radio2</li>
<li>
<input type="radio" name="letter_type" data-custom="Radio3" value="2">Radio3</li>
</div>
$("li").on("click", "input", function () {
$('#dg').datagrid('reload'); //reloads the grid
alert($(this).val()); //gets the value of input type radio
globalVar = $(this).val(); //assign the value to a global variable
$('#string').html(globalVar);
});
$('#dg').datagrid({
url: 'data_loader.php',
queryParams: { //this adds to the url ?ltype=valur
ltype: globalVar //assign the global variable here
}
});
//$('#string2').html(globalVar);
JSFiddle示例。
一种解决方案是再次调用.datagrid
。
$("li").on("click", "input", function () {
var val = $(this).val();
$('#string').html(val);
updateDataGrid(val);
});
updateDataGrid(); // this initial call may or may not be needed.
// if the grid should load something on start up
// then pass a parameter to it here.
function updateDataGrid(query) {
$('#dg').datagrid({
url: 'data_loader.php',
queryParams: {
ltype: query
}
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://www.jeasyui.com/easyui/jquery.easyui.min.js"></script>
<link href="http://www.jeasyui.com/easyui/themes/default/easyui.css" rel="stylesheet"/>
<hr>Filter
<hr>
<div class="adv_filter">
<li>
<input type="radio" name="letter_type" data-custom="Radio1" value="0">Radio1</li>
<li>
<input type="radio" name="letter_type" data-custom="Radio2" value="1" checked="checked">Radio2</li>
<li>
<input type="radio" name="letter_type" data-custom="Radio3" value="2">Radio3</li>
</div>
<hr>
<table class="easyui-datagrid" id="dg" title="Basic DataGrid" style="width:700px;height:250px" data-options="singleSelect:true,collapsible:true">
<thead>
<tr>
<th data-options="field:'itemid',width:80">Item ID</th>
<th data-options="field:'productid',width:100">Product</th>
<th data-options="field:'listprice',width:80,align:'right'">List Price</th>
<th data-options="field:'unitcost',width:80,align:'right'">Unit Cost</th>
<th data-options="field:'attr1',width:250">Attribute</th>
<th data-options="field:'status',width:60,align:'center'">Status</th>
</tr>
</thead>
</table>
<hr>
<!-- debug -->inside
<div id="string"></div>
<hr>outer
<div id="string2"></div>
相关文章:
- 如何在JQuery函数中定义一个值,然后调用另一个函数并使用该值
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 在另一个函数中使用变量this
- 在另一个函数成功结束后调用该函数
- 使用JS函数来使用另一个函数的语法?node.js
- 嵌套到另一个函数中的Fancybox函数;不起作用
- javascript函数将数据添加到屏幕,但随后被另一个函数覆盖
- 如何在不预定义的情况下将javascript函数传递到另一个函数中
- 从另一个函数获得$this值
- 如何记录调用另一个函数的函数的返回值
- 它在另一个函数中嵌套后不会输出文本
- 如何将自动完成的值传递到另一个函数中
- 将一个函数作为参数传递给javascript中的另一个函数
- 从另一个函数延迟解析的返回
- Javascript:OnChange事件,将数组变量传递给另一个函数
- 通过引用Javascript中的另一个函数来传递对象方法
- 将变量值传递给另一个函数
- 运行“;非“;单击另一个函数中的函数仅一次
- 用javascript将参数从一个函数传递到另一个函数
- 如何在另一个函数完成后运行