Created
October 25, 2014 08:26
-
-
Save hokuma/41bc63ebc20074caf428 to your computer and use it in GitHub Desktop.
東京メトロAPI+vue.js = トイレ検索 ref: http://qiita.com/halhide/items/840645c498ef68142048
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%div.container-fluid | |
%div.row | |
%div.form-group | |
%div.col-sm-10 | |
%select.form-control.stations{"v-model" => "selected", "v-on" => "change: onChange(this)"} | |
%option{"v-repeat" => "stations", "value" => "{{name}}"} {{title}} | |
%div.row.facilities | |
%div.inside-gate | |
%h3 改札内:{{insideCount}} | |
%div.list-group | |
%div.list-group-item{"v-repeat" => "facilities | filterBy 'true' in inside"} | |
%h4.list-group-item-heading {{name}} | |
%p.list-group-item-text | |
%span{"v-repeat" => "assistant"} {{{$value | pictgram}}} | |
%div.outside-gate | |
%h3 改札外:{{outsideCount}} | |
%div.list-group | |
%div.list-group-item{"v-repeat" => "facilities | filterBy 'false' in inside"} | |
%h4.list-group-item-heading {{name}} | |
%p.list-group-item-text | |
%span{"v-repeat" => "assistant"} {{{$value | pictgram}}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// トイレ情報View | |
facilitiesView = new Vue({ | |
el: ".facilities", | |
data: { | |
facilities: [] | |
}, | |
computed: { | |
insideCount: function() { | |
return _.filter(this.facilities, function(facility) { | |
return facility.inside; | |
}).length; | |
}, | |
outsideCount: function() { | |
return _.filter(this.facilities, function(facility) { | |
return !facility.inside; | |
}).length; | |
} | |
}, | |
methods: { | |
setStation: function(name) { | |
// FACILITIESはあらかじめ定義しておく | |
this.$data.facilities = FACILITIES[name]; | |
} | |
} | |
}); | |
// 駅選択 | |
stationsView = new Vue({ | |
el: ".stations", | |
data: { | |
stations: [], | |
selected: "" // 選択された駅 | |
}, | |
methods: { | |
updateStations: function() { | |
$data = this.$data; | |
navigator.geolocation.getCurrentPosition(function(position) { | |
// 最寄駅検索 | |
$.getJSON("/stations?lat=" + position.coords.latitude + | |
"&lon=" + position.coords.longitude).done(function(stations){ | |
$data.stations = stations; | |
if(stations.length > 0) { | |
$data.selected = stations[0].name | |
facilitiesView.setStation($data.selected); | |
} | |
}); | |
}); | |
}, | |
onChange: function() { | |
facilitiesView.setStation($data.selected); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment