10
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

monacaでスマホアプリを作ろう #4

Last updated at Posted at 2015-06-12

動的にリストを生成する

デザインはわかった。次は実装だ。
というわけで動的にリストを生成してみます。

生成したPage1Controller.jsに配列を定義

Page1Controller.js
app.controller('Page1Ctrl',function($scope){
    $scope.oss= [
        {"name":"KiKat", "kind":"android", "desc":"androidos4.4系です"},
        {"name":"JellyBean", "kind":"android", "desc":"androidos4.1-3系です"},
        {"name":"Honycomb", "kind":"android","desc":"androidos3.x系です"},
        {"name":"Mavericks", "kind":"osx","desc":"Mac 10.9"},
        {"name":"Mountain Lion", "kind":"osx", "desc":"Mac 10.8"},
        {"name":"Lion", "kind":"osx","desc":"Mac 10.7"},
        {"name":"SnowLeopard", "kind":"osx", "desc":"Mac 10.6"},
        ];
}) ;
    

page1.htmlを修正

page1.html
<ons-page>
<div ng-controller="Page1Ctrl">
  <ons-toolbar>
    <div class="center">List With Header</div>
  </ons-toolbar>

  <ons-list>
    <ons-list-header>Versions</ons-list-header>
    
    <ons-list-item modifier="chevron" ng-repeat="os in oss">
    {{os.name}}
    </ons-list-item>
  </ons-list>
</div>
</ons-page>

スクリーンショット 2015-06-12 16.12.43.png

さらに修正して

page1.html
<ons-page>
<div ng-controller="Page1Ctrl">
  <ons-toolbar>
    <div class="center">List With Header</div>
  </ons-toolbar>

  <ons-list>
    <ons-list-header>Android Versions</ons-list-header>
    <ons-list-item modifier="chevron" ng-repeat="os in oss" ng-if="os.kind == 'android'">
    {{os.name}}
    </ons-list-item>
    
    <ons-list-header>MacOSX Versions</ons-list-header>
    <ons-list-item modifier="chevron" ng-repeat="os in oss" ng-if="os.kind == 'osx'">
    {{os.name}}
    </ons-list-item>

    
  </ons-list>
</div>
</ons-page>

スクリーンショット 2015-06-12 16.15.26.png

これで静的なコードと表示と同じになりました。

10
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?