function helloworld(name){ console.log("hello!!!!!"+name) } var name="zhangsan"; eval("helloworld(name)");
代码粘贴到谷歌的控制台能够看到
hello!!!!! zhangsan
能够使用这个功能----返回用户选择的某行数据。
<smcs-search-input-table table-uniqueflag="b" table-resultjson="jsonresulta" table-showcols="showtablecolsa" table-temprow="6" table-querycol="0,1" table-outcol="0" table-callback="gettabledata(data)" resultcache="true" > </smcs-search-input-table>
gettabledata(data)是用户自己定义函数。我会在directive封装标签的里面调用这个行数,把用户选择的某行数据以json对象返回给data.
</pre><pre name="code" class="javascript">//双击某行时,把选中的数据输出 $scope.selectRow = function (id){ if(id==1){ return;//标题行 } var trtdid="#"+tableuniqueflag+""+id+(parseInt(tableoutcol)+1);//取id var trtdval=$(trtdid).text();//取值 var trtdidarray=new Array();//<td>id数组 //trtdidarray = ["#b41", "#b42", "#b43"] var trtdvalarray=new Array();//<td>中内容数组 //trtdvalarray=["a王武", "男", "北京"] for(var i=0;i<cells;i++){ trtdidarray[i]="#"+tableuniqueflag+""+id+(parseInt(i)+1); //表格一行的数据 trtdvalarray[i]=$(trtdidarray[i]).text(); } console.log(colattrs); //colattrs=["testname", "sex", "addr"] //json格式 { "testname": "a张三", "sex": "男","addr":"天津","tel":"138"} data="{" for(var j=0;j<cells;j++){ data=data+‘\"‘+colattrs[j]+‘\"‘+":"+‘\"‘+trtdvalarray[j]+‘\"‘; if(j<(cells-1)){ data=data+"," } } data=data+"}" //调用用户再app.controller中定义的回调函数。 $scope.tablecallbackfun(JSON.parse(data)); //把选中的项填写到输入框 document.getElementById("inputable"+tableuniqueflag).value = trtdval; $(mydivlocation).css(‘display‘,‘none‘); } //选中某行并将值的字符串返回父页面 $scope.tablecallbackfun = function(data){ eval("$scope."+tablecallback); }
app.controller
(function(){ var app = angular.module(‘SMCS.App‘); app.controller(‘MedicareInstitutionInfoMaintainCtrl‘, [‘$scope‘,‘$http‘, ‘BaseURL‘,‘$modal‘,‘Modal‘,function($scope,$http,BaseURL,$modal,Modal){ //后台返回数据 $scope.jsonresulta = [{ "testname": "a张三", "sex": "男","addr":"天津","tel":"138"}, { "testname": "a张狗", "sex": "男","addr":"上海","tel":"138"}, { "testname": "a王武", "sex": "男","addr":"北京","tel":"138"}, { "testname": "a张武", "sex": "男","addr":"北京","tel":"138"}, { "testname": "a花木兰", "sex": "女","addr":"北京","tel":"138"} ]; $scope.showtablecolsa = [ { label: ‘姓名‘, map: ‘testname‘}, { label: ‘性别‘, map: ‘sex‘}, { label: ‘住址‘, map: ‘addr‘} ]; $scope.gettabledata = function(data){ //data json对象,能够取里面的属性,相比原来返回一个值更灵活 console.log("sex==="+data.sex); } }]); })()
时间: 2024-10-25 18:36:58