Skip to content

Instantly share code, notes, and snippets.

@wireframeslayout
Last active July 4, 2016 06:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wireframeslayout/e77b30ef571e0cedaccb407bda545104 to your computer and use it in GitHub Desktop.
Save wireframeslayout/e77b30ef571e0cedaccb407bda545104 to your computer and use it in GitHub Desktop.
すいません、ソースコードに不備がありました。。こちらを使ってください。
var App = App || {};
App = {
api_root: "/api/",
api_key: "phe15557a001b1",
Model: function (api_name, condition) {
this.root = App.api_root;
this.key = App.api_key;
this.version = App.api_version;
this.api_name = api_name;
this.condition = condition ? condition : {};
this.url = this.root;
},
View: function (model) {
this.model = model;
/// テンプレートをキャッシュ
this.template = _.template($('#list-card').html());
this.$el = $("#app_root");
},
init: function () {
var that = this;
var hotels = new this.Model("StockSearch", {
s_area: 137412,
stay_date: 20160803,
stay_count: 3,
adult_num: 1,
count: 5
});
hotels.get()
.done(function () {
debugger;
var list = new that.View(hotels);
list.render();
});
// 日付指定
$('.datepicker').pickadate({
format: "yyyymmdd"
});
// セレクトボタン
$('select').material_select();
}
};
/**
* データを取得・管理するためのオブジェクト
* @type {{get: Function, convertJSON: Function}}
*/
App.Model.prototype = {
/**
* Ajax通信を行いデータを取得するためのメソッド
* @returns {*}
*/
get: function () {
var that = this;
this.condition.key = this.key;
var param = {
condition: this.condition,
api_name: this.api_name
};
return $.get(this.url, param)
.done(function (resp) {
that.data = resp;
});
},
/**
* 取得したプランを返す
* @returns {*}
*/
getPlans: function () {
return typeof this.data.Plan != "undefined" && typeof this.data.Plan != "undefined" ? this.data.Plan : [];
},
toJSON: function (xml) {
var json_string = xml2json(xml);
// 不要な文字列が含まれるので削除
json_string = json_string.replace(/UNDEFINED|undefined/g, "");
return JSON.parse(json_string);
}
};
App.View.prototype = {
render: function () {
// イベントを設定
var $form = this.$el.find('form#search');
var that = this;
$form.on("submit", function (evt) { that.search(evt) });
// リストをレンダリングする
this.renderList();
},
renderList: function () {
var that = this;
var plans = this.model.getPlans();
var $root = this.$el.find("#results-wrap");
// 中身をリセット
$root.empty();
_.each(plans, function (plan) {
$root.append(that.template(plan));
});
},
/**
* 検索する
*/
search: function (evt) {
var that = this;
evt.preventDefault();
/**
* 検索ボタンを押した時の挙動を記述
*/
debugger;
// フォームの内容を取得し、検索条件を作成
// 新しくモデルを作成し、そのモデルを使って再レンダリングを実行
}
};
// 実行
App.init();
@wireframeslayout
Copy link
Author

変更点は下記の部分です

111行目あたり。

var that = this;
$form.on("submit", function (evt) { that.search(evt) });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment