video02_concepts - KoreaSenchaUserGroup/Lab1 GitHub Wiki
#VIDEO 02. [Concepts] Intro to List Component
์๋ฌธ : http://docs.sencha.com/touch/2-0/#!/video/list
๋ฒ์ญ : https://github.com/KoreaSenchaUserGroup/Lab1/wiki/video02_concepts
๊ธ์ด์ด : ์ด๋ฏผํธ (Github:tisohjung), ํ๊ตญ์ผ์ฐจ์ ์ ๊ทธ๋ฃน SenchaCon ๋ฒ์ญํ
#The List Component
Sencha Touch provides a list component which is ideal for presenting a index style list of items. In this tutorial we'll setup a basic list, then how to add an index bar and regroup the items together under marker. Finally we'll see how to reveal a detail panel which could show additional information about each item in the list.
์ผ์ฐจ ํฐ์น๋ ์ธ๋ฑ์ค ์คํ์ผ์ ๋ฆฌ์คํธ ์์ดํ ์ ์ ํฉํ ๋ฆฌ์คํธ ์ปดํฌ๋จํธ๋ฅผ ์ง์ํฉ๋๋ค. ์ด๋ฒ ๊ฐ์ข์์๋ ๊ฐ๋จํ ๋ฆฌ์คํธ๋ค ๋ง๋ค๊ณ ์ธ๋ฑ์ค๋ฐ์ ๋ง์ปค ์๋ ๋ฆฌ๊ทธ๋ฃนํ๋ ๋ฐฉ๋ฒ๋ฑ์ ๋ณด๊ฒ ์ต๋๋ค. ๋ง์ง๋ง์ผ๋ก ๋ฆฌ์คํธ ์์ ์ถ๊ฐ์ ์ธ ์์ดํ ์ ์ ๋ณด๋ฅผ ๋ณผ์์๋ ๋ํ ์ผ ํจ๋์ ๋ณด๊ฒ ์ต๋๋ค
00:25 Configure a basic list
Let's start by making a list component. In the view's directory we'll create a new file called PresidentList.js. We'll define a PresidentList class, taken care to spell it the same way as the file name. And we'll make it extend from the list component. We're not done just yet, we'll need to setup a couple of configuration options, but we'll come back and do that later. To populate the list with some data, we have to bind it with the data store.
์ฐ์ ์ ๋ฆฌ์คํธ ์ปดํฌ๋จํธ๋ฅผ ๋ง๋ค์ด๋ณด๊ฒ ์ต๋๋ค. viewํด๋ ์์ PresidentList.js ๋ผ๋ ๋ง์ผ์ ์๋ก ๋ง๋ค๊ฒ ์ต๋๋ค. PresidentList ํด๋์ค๋ฅผ ์ ์ํ๊ฒ ์ต๋๋ค, ํ์ผ ์ด๋ฆ๊ณผ ๋ค๋ฅด์ง ์๊ฒ ์ฃผํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ list ์ปดํฌ๋จํธ๋ฅผ ์์๋ฐ๋๋ก ํ๊ฒ ์ต๋๋ค. ์์ง ๋๋์ง ์์์ต๋๋ค, ๋ช๊ฐ์ง ํ๊ฒฝ ์ค์ ์ ํด์ผ๋์ง๋ง ์ ์ํ ๋ค์ ๋์์์ ํ๊ฒ ์ต๋๋ค. ๋ฆฌ์คํธ๋ฅผ ๋ฐ์ดํฐ๋ก ์ฑ์ฐ๊ธฐ ์ํด, ๋ฐ์ดํฐ ์ ์ฅ์์ ์ฐ๊ฒฐํด์ผํฉ๋๋ค.
We'll create a new file under store directory called Presidents.js. Here we define a president class which extends from the store class. We also have to define the fields of an individual record. In the model directory we'll create a new file called President.js. Here we'll define a President class which extends from the model class. In the config object we specify 3 fields firstname, middleInitial, and lastName. That's all we need to do for the model for now.
store ํด๋ ์์ President.js ๋ผ๋ ์ ํ์ผ์ ๋ง๋ญ๋๋ค. ์ฌ๊ธฐ์ Storeํด๋์ค๋ฅผ ์์๋ฐ๋ president ํด๋์ค๋ฅผ ์ ์ํฉ๋๋ค. ๋ํ ๊ฐ๊ฐ์ ๊ธฐ๋ก์ ํ๋๋ฅผ ์ ์ํด์ผํฉ๋๋ค. model ํด๋์ President.js ํ์ผ์ ์์ฑํฉ๋๋ค. ์ฌ๊ธฐ์ Modelํด๋์ค๋ฅผ ์์๋ฐ๋ President ํด๋์ค๋ฅผ ์ ์ํฉ๋๋ค. config ๊ฐ์ฒด์ 3๊ฐ์ง ['firstName', 'middleInitial', 'lastName']์ ๋ช ์ํฉ๋๋ค. ์ผ๋จ ๋ชจ๋ธ์ ๋์ ๋๋ค.
Let's switch back to the store and configure it so it loads a collection of president records. We could configure the store with a proxy, so that it fetches record from a server, or from local storage. But we'll keep things simple here, and define the data inline. Note that the fields of each item in the data list, correspond to those we set up in the module.
๋ค์ store๋ก ๋์๊ฐ์ president ๊ธฐ๋ก์ ๊ฐ์ ธ์ค๊ฒ ์ค์ ํฉ๋๋ค. ํ๋ก์๋ก ์ค์ ํด์ ์๋ฒ์์ ๊ธฐ๋ก์ ๊ฐ์ ธ์ค๊ฒ ํ ์๋, ๋ก์ปฌ์ ์ฅ์์์ ๊ฐ์ ธ์ค๊ฒ ํ ์๋ ์์ต๋๋ค. ํ์ง๋ง ๊ฐ๋จํ๊ฒ ๋ฐ์ดํฐ ์ธ๋ผ์ธ์ผ๋ก ์ ์ํ๊ฒ ์ต๋๋ค. ๋ฐ์ดํฐ ๋ฆฌ์คํธ์ ๊ฐ๊ฐ์ ํ๋๊ฐ ๋ชจ๋์ ์ค์ ํ๊ฒ๊ณผ ์ผ์นํ๋๊ฒ์ ๋ณผ ์ ์์ต๋๋ค.
Now that we've setup the module and the store, we can bind them to list component. We'll configure our president list so that it references the presidents store. We also have to tell our component how to represent each item in the list. We'll simply show the firstName, and the lastName in the itemTpl. Now lets switch to the app.js file. We want to create an instance of the presidentList class when the application launches. We can do so by adding our custom component to the viewport inside the launch function. We also need to list each of our custom classes as a requirement for the application. We can reference them as the models, stores and views objects. Now if we take a look in the browser, we should find a vanilla version of the list view.
์ด์ ๋ชจ๋๊ณผ ์ ์ฅ์๋ฅผ ์ค์ ํ์ผ๋, ๋ฆฌ์คํธ ์ปดํฌ๋จํธ์ ์ฐ๊ฒฐ์์ผ๋ณด๊ฒ ์ต๋๋ค. PresidentList๋ฅผ ์ค์ ํด Presidents ์ ์ฅ์๋ฅผ ์ฐธ์กฐํ๊ฒ ํ๊ฒ ์ต๋๋ค. ๋ํ ์ปดํฌ๋จํธ๊ฐ ๊ฐ๊ฐ์ ๋ฆฌ์คํธ์ ์๋ ์์ดํ ๋ค์ ์ด๋ป๊ฒ ๋ณด์ฌ์ค์ง ์๋ ค์ค๋๋ค. ๊ฐ๋จํ itemTpl์์ firstName๊ณผ lastName์ ๋ณด์ฌ์ฃผ๋๋ก ํ๊ฒ ์ต๋๋ค. ์์ด์ app.js ํ์ผ๋ก ๊ฐ๊ฒ ์ต๋๋ค. ์ดํ๋ฆฌ์ผ์ด์ ์ด ์ผ์ง๋ฉด presidentList ํด๋์ค์ ์ธ์คํด์ค๋ฅผ ๋ง๋ค๊ณ ์ถ์ต๋๋ค. ๊ทธ๋ฌ๊ธฐ ์ํด์ ์ฐ๋ฆฌ๊ฐ๋ง๋ ์ปค์คํ ์ปดํฌ๋จํธ๋ฅผ launchํจ์์ Viewport์์ ๋ฃ์ต๋๋ค. ๋ํ ์ดํ๋ฆฌ์ผ์ด์ ์ ํ์์์๋ก ๊ฐ๊ฐ์ ์ปค์คํ ํด๋์ค๋ฅผ ๋์ดํฉ๋๋ค. models, stores์ views ๊ฐ์ฒด๋ก ์ฐธ์กฐ ํ ์ ์์ต๋๋ค. ์ด์ ๋ธ๋ผ์ฐ์ ธ์์ ๋ณด๋ฉด, vanilla version์ ๋ฆฌ์คํธ๋ทฐ๋ฅผ ๋ณผ์์์ต๋๋ค(์ญ ๋ฐ๋๋ผ๋ฒ์ ผ? ์ด๊ฐ๋จ ํ๋กํ ํ์ ๊ฐ์๊ฑธ ๋งํ๋๋ฏ? ์๋๋ฉด ๊ท๊ตฌ๋ ์ด ์ด์ํ๊ฑฐ๋;;;).
03:06 Group records by lastName and add an indexBar
The list class includes a configuration property called grouped. It's false by default, but if we set it to true, we can group the items in a list together. When grouped is set to true it is a requirement that the store associated with the list, implements the function called grouper. In this case we want to make this method return the first letter of the lastName field. At the moment the names are listed in the order which they were created. If we're going to group together the lastNames with the same initial letter, then we should also sort the list by the last name. When we refresh the browser, you'll see that the names are grouped together by last name. The list also includes a property called indexBar. Setting this to true, adds an index to the list view, making it easy to jump to a letter group.
๋ฆฌ์คํธ ํด๋์ค๋ grouped๋ผ๋ ์ค์ ๋ณ์๋ฅผ ํฌํจํฉ๋๋ค. ๋ํดํธ๊ฐ์ false์ ๋๋ค, ํ์ง๋ง true๋ก ๋ฐ๊พธ๋ฉด ๋ฆฌ์คํธ์์๋ ์์ดํ ์ ๊ทธ๋ฃนํ ํ ์ ์์ต๋๋ค. grouped๊ฐ true๊ฐ์ผ๋ ๋ฆฌ์คํธ์ ์ฐ๊ฒฐ๋์๋ ์ ์ฅ์(store)๊ฐ grouperํจ์๋ฅผ ํฌํจํด์ผํฉ๋๋ค. ์ฌ๊ธฐ์์๋ lastName ํ๋์ ์ฒซ๋ฒ์งธ ๋ฌธ์๋ฅผ ๋ฐํํ๊ฒ ํ๊ฒ ์ต๋๋ค. ํ์ฌ๋ ๋ฆฌ์คํธ์ ์ด๋ฆ์ด ๋ง๋ค์ด์ง ์์ผ๋ก ์ถ๋ ฅ์ด ๋ฉ๋๋ค. ๋ง์ผ ์ฌ๊ธฐ์ lastName๋ค์ ์ํ๋ฒณ๋ณ๋ก ๊ทธ๋ฃน์ํค๋ ค๋ฉด lastName์ ์ํ๋ฒณ ์ ๋ ฌํด์ผํฉ๋๋ค. ๋ธ๋ผ์ฐ์ ธ๋ฅผ ์๋ก๊ณ ์น๋ฉด ์ด๋ฆ์ด lastName์์ผ๋ก ๊ทธ๋ฃน์ ๋ ฌ๋์๋ ๊ฒ์ ๋ณผ ์ ์์ต๋๋ค. ๋ฆฌ์คํธ๋ indexBar๋ผ๋ ์์ฑ๋ ๊ฐ์ง๊ณ ์์ต๋๋ค. ์ด๊ฒ์ true๊ฐ์ ์ฃผ๋ฉด ๋ฆฌ์คํธ๋ทฐ์ ์ธ๋ฑ์ค๋ฅผ ๋ณด์ฌ์ค๋๋ค. ์ด์ ๊ทธ๋ฃน์ฐพ๊ธฐ ์ฐธ ์ฝ์ฃ ?
04:05 Show a detail view
So far we have a nice looking list. But wouldn't it be more useful if we can use a detail panel for each item? We'll start by defining a function on the list view called onItemDisclosure. For now we'll just make it log a message to the console. If we test it in the browser we'll see that each list item now has a disclosure icon. When tapped, a message appears on the console. Rather then handling the disclosure event inside of the view, we're going to do it in the controller. So let's replace the function with a boolean value of true. This simply tells the view to include a disclosure icon without specifying its' behavior.
ํ์ฌ์ํ๋ก๋ ๋ฆฌ์คํธ๊ฐ ๋ณด๊ธฐ ์ข์ต๋๋ค. ํ์ง๋ง ๋ํ ์ผํจ๋์ด(์ฐ์ธก์ํด๋ฆญํ์) ์์ผ๋ฉด ๋ ์ข๊ฒ ์ฃ ? ์ฐ์ onItemDisclosure์ด๋ผ๋ ํจ์๋ฅผ ๋ํ ์ผ ๋ทฐ์ ์ ์ํด์ฃผ๊ฒ ์ต๋๋ค. ์ผ๋จ์ ์ฝ์์ ๋ฉ์ธ์ง ์ถ๋ ฅ๋ง ํ๊ฒ ํด๋๊ฒ ์ต๋๋ค. ๋ธ๋ผ์ฐ์ ธ์์ ์คํํด๋ณด๋ฉด, ๊ฐ๊ฐ์ ๋ฆฌ์คํธ ์์ดํ ๋ค์ด ๋์คํด๋ก์ ธ ์์ด์ฝ์ ๋๊ณ ์์ต๋๋ค. ๋๋ฌ๋ณด์๋ฉด, ์ฝ์์ ๋ฉ์ธ์ง๊ฐ ์ถ๋ ฅ๋ฉ๋๋ค. ๋์คํด๋ก์ ธ ์ด๋ฒคํธ๋ฅผ ๋ทฐ์์ ์ฒ๋ฆฌํด์ฃผ๋ ๋์ ์ปจํธ๋กค๋ฌ ์์๋ค ํ๊ฒ ์ต๋๋ค. ์ผ๋จ ํจ์๋ฅผ Boolean ๋ณ์๋ก true๋ก ๋ฐ๊พธ๊ฒ ์ต๋๋ค. ์ด๊ฒ์ ๊ฐ๋จํ ๋์คํด๋ก์ ธ์์ด์ฝ์ ์ถ๊ฐ๋ง ํด์ฃผ๊ณ ๋ฌด์์ ํ ์ง๋ ์ ์ํ์ง ์์ต๋๋ค.
We'll implement the disclosure handler soon. But first let's consider what we've got in our application right now. The view port contains a single list component which currently occupies the full screen. We're going to have to add a second component for the detail view, as well as a container with a card layout to manage the 2 views. In this case we'll use the navigation review component as our container. When the application launches, the navigation view will only contain a single card, our list. But when the user taps a disclosure icon, we'll create a new detail view and push it onto the container.
๋์คํด๋ก์ ธ ํธ๋ค๋ฌ๋ ์ ์ํ ๋ค์ ์ ์ํ๊ฒ ์ต๋๋ค. ์ผ๋จ์ ์ดํ๋ฆฌ์ผ์ด์ ์ ๋ญ๊ฐ์๋์ง ํ๋ฒ ๋ณด๊ฒ ์ต๋๋ค. ๋ทฐํฌํธ๋ ํ์ฌ ์ ์ฒดํ๋ฉด์ ์ฐจ์งํ๊ณ ์๋ ํ๋์ ๋ฆฌ์คํธ ์ปดํฌ๋จํธ๋ฅผ ํฌํจํ๊ณ ์์ต๋๋ค. ์ด์ ๋ํ ์ผ๋ทฐ๋ฅผ ์ํด์ ๋๋ฒ์งธ ์ปดํฌ๋ํธ๋ฅผ ์ถ๊ฐํด์ผ๋ฉ๋๋ค. ๋ํ ๋๊ฐ์ ๋ทฐ๋ฅผ ๊ด๋ฆฌํ๊ธฐ์ํ ์นด๋๋ ์ด์์์ด ์๋ ์ปจํ ์ด๋๊ฐ ํ์ํฉ๋๋ค. ์ฌ๊ธฐ์๋ ๋ค๋น๊ฒ์ด์ ๋ทฐ ์ปดํฌ๋ํธ๋ฅผ ์ปจํ ์ด๋๋ก ์ฐ๊ฒ ์ต๋๋ค. ์ฑ์ด ์คํ๋๋ฉด ๋ค๋น๊ฒ์ด์ ๋ทฐ๋ ํ๊ฐ์ ์นด๋๋ง์ ๊ฐ๊ณ ์์ต๋๋ค, ํ์ง๋ง ๋์คํด๋ก์ ธ ์์ด์ฝ์ ํด๋ฆญํ๊ฒ ๋๋ฉด, ์๋ก์ด ๋ํ ์ผ๋ทฐ๋ฅผ ์ปจํ ์ด๋๋ก ํธ์ฌ(์นํ์ค) ํด์ค๋๋ค.(์คํํํ์ ๋ทฐ ๊ด๋ฆฌ)
The navigation view automatically adds a tool bar with a back button. When pressed the back button pops the top most view from the stack, revealing the list again. Let's start by defining a detail view. We'll create a new file in the view's directory called PresidentDetail. This extends the panel class. Later on we'll set the title and html properties dynamically. But for now, we'll just use couple of place holder values.
๋ค๋น๊ฒ์ด์ ๋ทฐ๋ ์๋์ผ๋ก ํด๋ฐ์ ๋ค๋ก๊ฐ๊ธฐ ๋ฒํผ์ ๋ง๋ค์ด์ค๋๋ค. ๋๋ฅด๋ฉด ์คํ์์ ์ต์์์ ๋ทฐ๋ฅผ ํ(๋นผ์ค)ํด์ฃผ๋ฉฐ ๋ฆฌ์คํธ๋ก ๋์๊ฐ๋๋ค. ์ฐ์ ๋ํ ์ผ๋ทฐ๋ฅผ ์ ์ํด์ฃผ๊ฒ ์ต๋๋ค. PresidentDetail ํด๋์ ์๋ก์ด ํ์ผ์ ์์ฑํฉ๋๋ค. ํจ๋ ํด๋์ค๋ฅผ ์์ํด์ค๋๋ค. ๋์ค์ title๊ณผ html ๋ณ์๋ฅผ ๋์ ์ผ๋ก ๋ง๋ค์ด์ฃผ๊ฒ ์ต๋๋ค. ํ์ง๋ง ์ผ๋จ์ ๋์ฒด์ ์ธ ๊ฐ์ ๋ฃ์ด๋๊ฒ ์ต๋๋ค.
Next we'll create the navigation view. We've already got a file here called "Main.js", so let's use that. We'll change it from Ext.Panel into a navigation.View. Since this view is going to act as a container our list and detail cards, we have to specify these as requirements. When this class is instantiated we want it to contain a single item, a presidentlist. Here we're using the xtype which is a short hand for referencing classes. Let's make sure we've declared an xtype for each of our custom components. We'll call this main class mainpanel. The list panel can be referenced by presidentlist, and the detail panel can be referenced as presidentdetail.
๋ค์์ ๋ค๋น๊ฒ์ด์ ๋ทฐ๋ฅผ ๋ง๋ค์ด๋ณด๊ฒ ์ต๋๋ค. ์ด๋ฏธ ์๋ Main.js ๋ผ๋ ํ์ผ์ ์ฌ์ฉํ๊ฒ ์ต๋๋ค. Ext.Panel์ navigation.View๋ก ๋ฐ๊ฟ์ฃผ๊ฒ ์ต๋๋ค. ์ด๋ทฐ๋ ๋ฆฌ์คํธ์ ํฐํ ์ผ์นด๋๋ค์ ์ปจํ ์ด๋ ์ญํ ์ ํ ๊ฒ์ด๊ธฐ ๋๋ฌธ์, requirements(requires:)๋ฅผ ์ ์ํด์ค์ผํฉ๋๋ค. ์ด ํด๋์ค๊ฐ ์ด๊ธฐํ๋๋ฉด presidentlist๋ผ๋ ํ๋์ ์์ดํ ์ ํฌํจํ๊ณ ์๊ธธ ์ํฉ๋๋ค. ์ฌ๊ธฐ์๋ ์ฐธ์กฐ ํด๋์ค๋ฅผ ๋งํ๋ xtype์ ์ฌ์ฉํฉ๋๋ค. ๊ฐ๊ฐ์ ์ปค์คํ ์ปดํฌ๋ํธ์ xtype์ ์ ์ธํ๋์ง ์ฃผ์ํ์๊ธธ ๋ฐ๋๋๋ค. ์ด ๋ฉ์ธ ํด๋์ค๋ฅผ mainpanel์ด๋ผ๊ณ ์ด๋ฆ์ง๊ฒ ์ต๋๋ค. ๋ฆฌ์คํธ ํจ๋์ presidentlist๋ก ์ฐธ์กฐํ๊ณ ๋ฆฌ์คํธํจ๋์ presidentdetail๋ก ์ฐธ์กฐ ํ ์ ์๊ฒ ํ๊ฒ ์ต๋๋ค.
Now we'll switch to app.js file. Right now we are adding a presidentList to the view port. Let's change this by adding a main panel instead. We also have to update the views requirement to reference the main view. Now let's see what this looks like in the browser. It's almost the same as before except this tool bar. If we give our list component a title, then it will appear in the toolbar like so. Now all we have to do is wire up the handler for these disclosure buttons. Let's open up our main controller. This is where we'll add logic for handling the onItemDisclosure event. Inside of our control object, we'll add a reference to the presidentlist component. We want to trigger a function when the disclose event is captured by this component. For now we'll just log a message to the console. Let's check it in the browser to see if it works. Yes, clicking the disclosure icon logs a message, as expected.
app.jsํ์ผ์ ์ด์ด๋ณด๊ฒ ์ต๋๋ค. ํ์ฌ๋ ๋ทฐํฌํธ์ presidentList๋ฅผ ์ถ๊ฐํด๋จ์ต๋๋ค. ์ด๊ฒ์ Main ํจ๋๋ก ๋ฐ๊ฟ์ฃผ๊ฒ ์ต๋๋ค. ๋ํ views๋ฅผ Main ๋ทฐ๋ฅผ ์ฐธ์กฐํ๊ฒ ๋ฐ๊ฟ์ค์ผํฉ๋๋ค. ์ด์ ๋ธ๋ผ์ฐ์ ธ๋ฅผ ํ๋ฒ ๋ณด๊ฒ ์ต๋๋ค. ์๊น์ ๊ณผ ๊ฑฐ์ ๋น์ทํ๋ฐ ์์ ํด๋ฐ๊ฐ ์๊ฒผ์ต๋๋ค. ๋ฆฌ์คํธ์ปดํฌ๋ํธ์ title์ ์ฃผ๋ฉด ํด๋ฐ์ ๋ณด์ฌ์ง๊ฒ๋ฉ๋๋ค. ์ด์ ๋์คํด๋ก์ ธ๋ฒํผ์ ํธ๋ค๋ฌ๋ง ๋ง๋ค์ด์ฃผ๋ฉด ๋ฉ๋๋ค. ๋ฉ์ธ์ปจํธ๋กค๋ฌ๋ฅผ ์ด์ด๋ณด๊ฒ ์ต๋๋ค. ์ฌ๊ธฐ์ onItemDisclosure ์ด๋ฒคํธ ํธ๋ค๋ฌ๋ฅผ ์ถ๊ฐํ๊ฒ ์ต๋๋ค. control ๊ฐ์ฒด์ presidentlist ์ปดํฌ๋ํธ ์์์ ์ถ๊ฐํ๊ฒ ์ต๋๋ค. diclose ์ด๋ฒคํธ๊ฐ ๋ค์ด์ค๋ฉด ์คํํ๋ ํจ์๋ฅผ ๋ง๋ค๊ฒ ์ต๋๋ค. ์ผ๋จ์ ์ฝ์์ ๋ฉ์์ง ์ถ๋ ฅ์ผ๋ก ํด๋๊ฒ ์ต๋๋ค. ๋ธ๋ผ์ฐ์ ธ๋ก ๋์๊ฐ์ ์ ๋์๊ฐ๋์ง ํ์ธํ๊ฒ ์ต๋๋ค. ์์ค ์์๋๋ก ๋์คํด๋ก์ ธ ์์ด์ฝ ํด๋ฆญํ๋ ๋ฉ์ธ์ง ์ถ๋ ฅ์ด๋๋ค์ ์๋๋ค์ ๋์ต๊ณ ์ผ(์ญ?).
Rather then defining an anonymous function inline, let's create a function called showDetail. We'll call this when the presidentlist disclose event fires. The implement is quite simple. We want to fetch reference to the navigation view, and push onto it, a new detail panel. To make this work, we first have to define the getMain function. When the application launches it automatically creates a getter function for each key defined in the refs configuration. So if we create a key called main, sencha touch will give us a getmain function for free. We don't have to implement function, we only need to provide component query selector. In this case the xtype mainpanel will do the job. Let's have a look at this in the browser. When we click a load disclosure icon it shows a panel with "Hello, World!" text.
์์์ ํจ์๋ฅผ ์ ์ํด์ฃผ๋ ๋์ showDetail์ด๋ ํจ์๋ฅผ ๋ง๋ค์ด์ฃผ๊ฒ ์ต๋๋ค. ์ด ํจ์๋ฅผ presidentlist์ disclose์ด๋ฒคํธ๊ฐ ๋ฐ์ํ๋ฉด ๋ถ๋ฅด๊ฒ ์ต๋๋ค. ์คํํ๋๊ฒ์ ๊ฐ๋จํฉ๋๋ค. ๋ค๋น๊ฒ์ด์ ๋ทฐ์ ์ฐธ์กฐ๋ฅผ ๊ฐ์ ธ์์ ์๋ก์ด ๋ํ ์ผ ํจ๋์ ํธ์ฌํด์ค๋๋ค. ์ด๊ฒ ๋์๊ฐ๊ฒ ํ๋ ค๋ฉด ์ฐ์ ์ getMain ํจ์๋ฅผ ์ ์ํด์ค์ผํฉ๋๋ค. ์ฑ์ด ์คํ๋๋ฉด refs ์ค์ ์ ๊ฐ๊ฐ์ ํค์ ๋ํด getter ํจ์๊ฐ ์๋์ผ๋ก ๋ง๋ค์ด์ง๋๋ค. ๊ทธ๋์ main์ด๋ผ๋ ํค๋ฅผ ๋ง๋ค๋ฉด, ์ผ์ฐจ ํฐ์น๊ฐ ์๋์ผ๋ก getMain ํจ์๋ฅผ ๋ง๋ค์ด์ค๋๋ค. ํจ์๋ฅผ ๋ฐ๋ก ๊ตฌํํ ํ์์์ด, ์ปดํฌ๋ํธ ์ฟผ๋ฆฌ ์ ๋ ํฐ๋ง ์ฃผ๋ฉด ๋ฉ๋๋ค. ์ฌ๊ธฐ์๋ xtype mainpanel ์ด ํด์ค๋๋ค. ๋ธ๋ผ์ฐ์ ธ์์ ํ๋ฒ ๋ณด๊ฒ ์ต๋๋ค. ๋์คํด๋ก์ ธ ์์ด์ฝ์ ํด๋ฆญํ๋ฉด "Hello, World!"๋ผ๊ณ ์ฐ์ฌ์ง ํจ๋์ด ๋น๋๋ค.
Note that the navigation view has automatically added a back button. Which let's a step back to the list view. Next we want to customize the detail panel, so that it shows the information about the record that was disclosed. Let's start by looking up the documentation for the disclose event. The function signature contains 6 arguments. But the only one we are going to actually need is this one, the record. We'll add the first 2 argument to the showDetail function. Now when we instantiate the new detail card, we can pass the record data along with it. Let's switch to the detail panel and change the text. Instead of using "Hello, World!" as static html, we'll switch to an xtemplate and use the first name field in the greeting. This place holder will be replaced with data from the selected record. Check it out in the browser. When we click on the disclosure icon, we get a message customized for that record. There's one final customization we should make. Instead of having a title that says details, let's update that dynamically as well. In our president model, we can create a function called fullName. This includes the middleInitial, but only if one is given. Now in our disclosure handler, we can call this function using the return values to set the title of our detail card. Check it out in the browser and we should see a customized title, each time we disclose the detail panel for the record.
๋ค์ด๊ฒ์ด์ ๋ทฐ๊ฐ ์๋์ผ๋ก ๋ค๋ก๊ฐ๊ธฐ ๋ฒํผ์ ๋ง๋ค์ด์ค๊ฑธ ๋ณผ ์ ์์ต๋๋ค. ํด๋ฆญํ๋ฉด ๋ค์ ๋ฆฌ์คํธ๋ทฐ๋ก ๋์๊ฐ๋๋ค. ๋ค์์ ๋ํ ์ผ ํจ๋์ ์ด๋ค ์๋ฃ๋ฅผ ํตํด ๋ค์ด์๋์ง ๋ณด์ฌ์ฃผ๊ฒ ์ปค์คํฐ๋ง์ด์ฆํ๊ณ ์ถ์ต๋๋ค. ์ฐ์ ๋ํ๋จผํธ์ disclose ์ด๋ฒคํธ์ ๋ํด ์ฐพ์๋ณด๊ฒ ์ต๋๋ค. ํจ์์ ์์๋ 6๊ฐ์ ๊ฐ์ด ๋ค์ด์์ต๋๋ค, ๊ทธ์ค ํํ๊ฒ์ recordํ๋๋ฉด ๋ฉ๋๋ค. ์ ์ผ ์์ ๋๊ฐ ๊ฐ์ showDetailํจ์๊ฐ ๋ฐ๊ฒ ํ๊ฒ ์ต๋๋ค. ์ด์ ๋ํ ์ผ ์นด๋๋ฅผ ์ด๊ธฐํ์์ ๋ฐ์ดํฐ๊ฐ์ ๊ฐ์ ธ์ฌ์ ์์ต๋๋ค. ๋ํ ์ผ ํจ๋๋ก ๋์๊ฐ์ ํ ์คํธ๋ฅผ ๋ฐ๊ฟ๋ณด๊ฒ ์ต๋๋ค. Hello, World ๋์ xtemplate๋ฅผ ์ฌ์ฉํด์ ์ด๋ฆํ๋ ๊ฐ์ ์ถ๋ ฅํด๋ณด๊ฒ ์ต๋๋ค. ์ด ํ๋ ์ด์คํ๋๋ ์์ ๋ฐ์ดํฐ์์ ์ ํํ ๋ ์ฝ๋๋ก ๋์ฒด๋ฉ๋๋ค. ๋ง์ง๋ง์ผ๋ก ํ๊ฐ์ง ๋ ํด์ผ๋ฉ๋๋ค. ํ์ดํ์ details๋ผ๊ณ ํ๊ธฐ๋๋ ๋์ ์ด๊ฒ๋ ๋์ ์ผ๋ก ๋ฐ๊พธ๊ฒ ์ต๋๋ค. President์ Model์์ fullName์ด๋ผ๋ ํจ์๋ฅผ ๋ง๋ค๊ฒ ์ต๋๋ค. middleInitial์ด ์์์์๋ง ํ๊ธฐ๋๊ฒ ํ์ต๋๋ค. ์ด์ ๋์คํด๋ก์ ธ ํธ๋ค๋ฌ์์, ์์ ํจ์๋ฅผ ๋ถ๋ฌ ๋ฆฌํด๋๋ ๊ฐ์ผ๋ก title์ ์ค์ ํฉ๋๋ค. ์ฒดํท์์ ๋ธ๋ผ์ฐ์ ธ ํฌ์คํฐ๋ง์ด์ฆ ํ์ดํ ๋์คํด๋ก์ฆ ๋ฒํผ๋๋ฅผ๋๋ง๋ค ๋ฐ๋๋๋ค.
11:00 Outro
The code used in this demonstration can be found on the github. I've created a separate branch for every check point. So each time you see a card like this one, it means that you can checkout a snapshot of the code. In it comes the state at that point in the screen cast. You can find instructions on how to view these snapshots in the repository's readme file. github์ ๋ธ๋์น๋ก ๋๋ ์ ์์์์ ์๋ ๊ฑฐ๋ฏํฐํฐํ ์ฃผ์๋จ๋ฉด ๋ค ์ฐพ์๋ณผ ์ ์๋ต๋๋ค readmeํ์ผ์ ์๋ด๋ฌธ์๋ ๋ค ๋ค์ด์๋ต๋๋ค ์์ธํ ๋ฒ์ญ์ ์๋ตํฉ๋๋ค.