Summary of development skills | Things you don't know about imag.js

1. What are the standard JavaScript objects
in imag.js? The standard JavaScript objects in imag.js are Object, Function, Array, Boolean, Date, Math, Number, String, RegExp, Global Functions, JSON.

2. Why does the client prompt XML syntax error?

The code documentation of imag.js follows the strict XML syntax specification. Pay attention to the following points when developing:
  1. The text of labels, such as label, script, web, etc., may contain XML special symbols <, &, be careful to use CDATA to mark them.
  2. The attribute contains the special symbol & which needs to be escaped with &, for example: href="nextpage.jsp?username=Terry&password=123"
  3. The space between attributes cannot be missing, that is, the two attributes cannot be written together. Such as: <button style="color:red"onclick="alert(1);">button</button>, where style and onclick are connected.
  4. Attributes cannot be repeated, if such as: <button style="color:red" style="background:blue;">button</button>, two style attributes are defined.
  5. CDATA can no longer contain CDATA, such as: <web><![CDATA[<script><![CDATA[alert(0);]]></script>]]></web> , where CDATA is nested and an error occurs.

Note: If the code is ok on Android system, but it prompts XML syntax error on iOS system, please check the above two situations 3 and 4.

3. How to nest CDATA in JS script?

Sometimes it is necessary to nest CDATA in JavaScript, but this will report XML syntax errors, such as:

<script>

<![CDATA[

    $page.onload = function() {   

        var label = $C('<label><![CDATA[text&content]]></label>');

        $('row').add(label);

    };

]]>

</script>


At this point, you can call a JS method to generate CDATA by spelling a string, so as to avoid using CDATA directly, such as:

<script>

<![CDATA[

    function cdata(text) {

        return '<![' + 'CDATA[' + text + ']]' + '>';

    }

         

    $page.onload = function() {

        var label = $C('<label>' + cdata('text&content') + '</label>');

        $('row').add(label);

    };

]]>

</script>


4. How to introduce public JS files?

Using the include attribute of page, you can import multiple JS files. For details, please refer to: Importing JS Files .

5. How to pass parameters between

pages? There are two ways to pass parameters between pages:
one way is to pass parameters by URL, such as: $page.open('nextpage.xml?username=Terry'), please refer to Pass parameters .
Another way is to use the $phone.sessionStorage() or $phone.localStorage() method, please refer to Offline Storage for details .

6. How to remember the login user name and password?

There are three ways. 1. Use the remember property of the form control. 2. Use $phone.localStorage() to save the data. 3. Set a cookie in the server background to save the form data, and the cookie will be saved to the mobile client.

7. How to realize the automatic login function?

Set the parameters after user login on the server side to the client's cookie, the imag.js client will automatically bring the cookie information when accessing the server, and then the server will return the login success information to the client. The specific method is the same as the way that the PC-side browser implements automatic login.

8. How to access the background database?

There are two ways to access the background database in imag.js. One is to read the database data through the background program, and then use JSP, ASP and other scripts to output the imag.js tag. This method is similar to dynamic Web page. Another way is via $http.get() and $http.post() method to get server-side data, this way is similar to Ajax. For details, please refer to: Two ways for the imag.js client to access the background database. For the construction of the development environment, please refer to Product Help: Local Development and Debugging .

9. How to set page timer?

Use the $page.setTimeout() and $page.setInterval() methods to set the timer. For details, refer to: Page Methods .

10. How to use the gallery to browse a group of pictures?

The gallery function uses the $page.gallery() method, refer to: Gallery method .

11. How to display the tree structure?

To display a tree structure using a collapsible list, you need to set the collapsed property of ListItem. For details, refer to: Collapsible List .

12. How to use an index to sort a list?

To use an index to sort a list, you need to set the reuse="sort" of the list. For details, refer to: Index Sorted List .

13. How to implement paging up function?

First use the scrollToBottom() method of the list to position the scroll bar to the bottom, and then use the addTopMore() method to add data to the top of the list.

14. How to get IMEI, IMSI, MAC address and other mobile phone information?

Use the $phone.info() method to obtain mobile phone information such as IMEI, IMSI, and MAC address. For details, refer to: Client Information .

15. How to limit mobile phone operators?

Obtain operator information and control it through $phone.info()['operator']. For details, refer to: Limiting operators .

16. How to control the Android and iOS platforms to execute different codes?

Obtain the platform parameter through the $phone.info() method, and then use the if else conditional statement to control the execution of different codes on different platforms.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326627112&siteId=291194637