アプリ内購入のcordovaプラグインを使用してiTunesConnectから製品をプルしていますが、有効な製品(タイトル)をラジオボタンリストに表示したいと思います。
Store。( 'product')update関数はこれをレンダリングします(なぜ2回表示されるのかわかりませんか?!)
2015-12-27 10:59:12.158 Paypal3drupal[1059:18480] 200 - OK
2015-12-27 10:59:12.896 Paypal3drupal[1059:18480] product_item: {"id":"120points","alias":"120 Points","type":"consumable","state":"valid","title":"120 Points","description":"Get 120 points for asking questions","price":"€10,99","currency":"EUR","loaded":true,"canPurchase":true,"owned":false,"downloading":false,"downloaded":false,"transaction":null,"valid":true}
2015-12-27 10:59:12.897 Paypal3drupal[1059:18480] product_item: {"id":"120points","alias":"120 Points","type":"consumable","state":"valid","title":"120 Points","description":"Get 120 points for asking questions","price":"€10,99","currency":"EUR","loaded":true,"canPurchase":true,"owned":false,"downloading":false,"downloaded":false,"transaction":null,"valid":true}
2015-12-27 10:59:12.897 Paypal3drupal[1059:18480] product_item: {"id":"200points","alias":"200 Points","type":"consumable","state":"valid","title":"Points 200","description":"Get 200 points for everything","price":"€15,99","currency":"EUR","loaded":true,"canPurchase":true,"owned":false,"downloading":false,"downloaded":false,"transaction":null,"valid":true}
2015-12-27 10:59:12.897 Paypal3drupal[1059:18480] product_item: {"id":"200points","alias":"200 Points","type":"consumable","state":"valid","title":"Points 200","description":"Get 200 points for everything","price":"€15,99","currency":"EUR","loaded":true,"canPurchase":true,"owned":false,"downloading":false,"downloaded":false,"transaction":null,"valid":true}
2015-12-27 10:59:12.900 Paypal3drupal[1059:18480] \o/ STORE READY \o/
コルドバ 例 このような製品をレンダリング
// When any product gets updated, refresh the HTML.
store.when("product").updated(function (p) {
app.renderIAP(p);
});
そして
app.renderIAP = function(p) {
var elId = p.id.split(".").pop();
var el = document.getElementById(elId + '-purchase');
if (!el) return;
if (!p.loaded) {
el.innerHTML = '<h3>...</h3>';
}
else if (!p.valid) {
el.innerHTML = '<h3>' + p.alias + ' Invalid</h3>';
}
else if (p.valid) {
var html = "<h3>" + p.title + "</h3>" + "<p>" + p.description + "</p>";
if (p.canPurchase) {
html += "<div class='button' id='buy-" + p.id + "' productId='" + p.id + "' type='button'>" + p.price + "</div>";
}
el.innerHTML = html;
if (p.canPurchase) {
document.getElementById("buy-" + p.id).onclick = function (event) {
var pid = this.getAttribute("productId");
store.order(pid);
};
}
}
Drupalgapでラジオボタンウィジェットを動的にターゲットにしてデータを設定するにはどうすればよいですか?より具体的には、ラジオボタンのオプションと値を動的に設定するにはどうすればよいですか(オプション値= product_item_id 、オプションラベル= product_item.title)?
フォームドキュメントに基づく 例 送信ボタンでフォームを表示する静的な値を持つカスタムページがあります。
/**
* Implements hook_menu().
*/
function my_module_menu() {
try {
var items = {};
items['in-app'] = {
title: 'get points',
page_callback: 'drupalgap_get_form',
page_arguments: ['my_module_payment_form']
};
return items;
}
catch (error) {
console.log('my_module_menu - ' + error);
}
}
/**
* Define the form.
*/
function my_module_payment_form(form, form_state) {
try {
form.elements['points'] = {
type: 'radios',
title: 'Points',
options: {
0: 'cancel',
70: '70 Points', // should look something like product_item.id[0] : product_item.title[0]
120: '120 Points',
250: '250 Points'
},
default_value:0,
required: true
};
form.elements['submit'] = {
type: 'submit',
value: 'Buy points'
};
return form;
}
catch (error) { console.log('my_module_payment_form - ' + error); }
}
/**
* Define the form's submit function.
*/
function my_module_payment_form_submit(form, form_state) {
try {
drupalgap_alert('You selected ' + form_state.values['points'] + '!');
}
catch (error) { console.log('my_module_payment_form_submit - ' + error); }
}
pageshowコールバック を使用します:
function my_pageshow() {
// Retrieve the data from the server
// During the retrieval's success callback, place the items into the empty radio button widget.
}
フォームビルダー関数でラジオボタンを空のままにしてから、pageshow
コールバックを使用してラジオボタンの動的な入力を処理できます。