AngularJS custom label add callback function eval (), angularjseval

Source: Internet
Author: User

AngularJS custom label add callback function eval (), angularjseval

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

Paste the code to the Google console.

Hello !!!!! Zhangsan

You can use this function to return a row of data selected by the user.

<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) is a user-defined function. I will call this row in the ctive encapsulation label to return the data of a row selected by the user to the data as a json object.

</Pre> <pre name = "code" class = "javascript"> // double-click a row and output the selected data to $ scope. selectRow = function (id) {if (id = 1) {return; // header row} var trtdid = "#" + tableuniqueflag + "" + id + (parseInt (tableoutcol) + 1); // obtain idvar trtdval =$ (trtdid ). text (); // value var trtdidarray = new Array (); // <td> id Array // trtdidarray = ["# b41", "# b42 ", "# b43"] var trtdvalarray = new Array (); // <td> content Array // trtdvalarray = ["a wang Wu", "male ", "Beijing"] for (var I = 0; I <cells; I ++) {trtdidarr Ay [I] = "#" + tableuniqueflag + "" + id + (parseInt (I) + 1 ); // trtdvalarray [I] = $ (trtdidarray [I]). text ();} console. log (colattrs); // colattrs = ["testname", "sex", "addr"] // json format {"testname": "a Zhang San", "sex ": "male", "addr": "Tianjin", "tel": "138"} data = "{" for (var j = 0; j <cells; j ++) {data = data + '\ "' + colattrs [j] + '\"' + ":" + '\ "' + trtdvalarray [j] + '\"'; if (j <(cells-1) {data = data + ","} data = data + "}" // call the user to go to the app. the callback function defined in controller. $ Scope. tablecallbackfun (JSON. parse (data); // fill in the selected items in the input box document. getElementById ("inputable" + tableuniqueflag ). value = trtdval;((mydivlocation).css ('display', 'None');} // select a row and return the value string to the parent page $ 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) {// data returned in the background $ scope. jsonresulta = [{"testname": "a zhangsan", "sex": "male", "addr": "Tianjin", "tel": "138 "}, {"testname": "a dog", "sex": "male", "addr": "Shanghai", "tel": "138 "}, {"testname": "a Wang Wu", "sex": "male", "addr": "Beijing", "tel": "138" },{ "testname ": "a zhangwu", "sex": "male", "addr": "Beijing", "tel": "138" },{ "testname": "a Hua Mulan ", "sex": "female", "addr": "Beijing", "tel": "138"}]; $ scope. showtablecolsa = [{label: 'name', map: 'testname'}, {label: 'gender ', map: 'sex'}, {label: 'address', map: 'addr '}]; $ scope. gettabledata = function (data) {// data json object, which can take the attributes in it. It is more flexible than returning a value. console. log ("sex =" + data. sex) ;}}]) ;}) ()


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.