ArticleDirectory
- This series of directories
This series of directories
- Introduction to palm web OS
- Build a development environment in one of palm Application Development
- Palm application development 2: Learning from helloworld
- Detailed description of appinfo. JSON file in Palm application development 3
- Four palm Application Models for Palm Application Development
Scene (scenario) template
Through the previous sections, we have learned that scene is an important part of the palm application. The Palm application is composed of scene, and each scene is a scenario on the entire stage, or you can understand it as a card. Then, when we create an application, we create scene one by one and organize these scene according to certain logic to form a simple application. Since scene is so important, then we will study scene separately. First, create a scene in Eclipse: select the application-> file-> New-other... The create type dialog box is displayed as follows:
In the dialog box, select mojo scene under the palm applaction and next, the following dialog box is displayed:
Enter the scene name and click Finish to complete the creation.
After scene is created, let's see what changes have taken place in the entire project? Look at the hellowworld directory.
We can see that there are two more files APP/assistants/main-assistant.js and APP/views/main/main-scene.html while there is also a configuration in sources. JSON, such:
This configuration is required. The JS resource files of the entire project must be configured here (as described above ).
It is not hard to see that a scene template contains three aspects:
1. A controller is stored under the project APP/assistants. The file name is the name + "-assistant. JS "(such as: APP/assistants/main-assistant.js), it is responsible for scene navigation, logical data processing and so on.
2. A view is stored under APP/views/Main. Every time a scene is created, a sub-directory is created under APP/views and an HTML file is created in the sub-directory, the subdirectory name is the same as that used to create scene. The naming rule of a file is the name of the file when sceneis created, such as APP/views/main/main-scene.html, which interacts with the user.
3. Reference The JS file of the Controller to be applied in sources. JSON.
The View File is empty, and there is nothing. developers can use HTML, CSS, or mojo widgets in this file to design beautiful user interfaces. The Controller is much more important and complex. It controls how the interface is displayed, data logic, and so on. This file may be being written.ProgramIs the most important place.
Scene assistant Template
Every time you create a scene file and open the Controller file, we will find that the following created JSCodeFile, which is called scene assistant template:
One method and four events are automatically created when the main scene is created. People familiar with prototype should be familiar with such code.
Mainassistant: constructor used for system initialization and receiving parameters passed on the previous page (the constructor name is composed of the first letter of the name of the created scene + Assistant)
Setup: initializes the widget and system data.
Activate: events are triggered when the page is changed.
Deactivate: triggered when the current page exits or when this line is "Garbage Collection"
Cleanup: executed during page destruction, responsible for "Garbage Collection" and resource release.
The lifecycle of scene assistant is similar to that of the Asp.net page, but it is much simpler than Asp.net. Only these four events exist. The execution sequence of the pages is as follows:
Initialize (constructor) ---> setup ---> activate ---> deactivate ---> cleanup
Scene is a key point. It has been dealing with scene during the development of palm. It can develop more efficient palm applications by mastering the content contained in scene and its running cycle.