AngularJS自己定義標籤加入回呼函數eval()

來源:互聯網
上載者:User

標籤:modal   回呼函數   oda   返回   .json   rip   表格   utc   angularjs   

function helloworld(name){ console.log("hello!!!!!"+name)} var name="zhangsan";eval("helloworld(name)"); 

代碼粘貼到Google的控制台能夠看到

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);//取idvar 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);}}]);})()


AngularJS自己定義標籤加入回呼函數eval()

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.