質問編集履歴
2
実際のソースコードを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -165,3 +165,369 @@
|
|
165
165
|
実際の処理画面は以下URLにあります。
|
166
166
|
|
167
167
|
[座標計算 | Coordinate calculation](http://hogehogeago.xsrv.jp/sokuryou/coordinateCalculation.html)
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
以下、実際のソースコード
|
178
|
+
|
179
|
+
```JavaScript
|
180
|
+
|
181
|
+
*** coordinateCalculation-activity.js ***
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
$(function () {
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
// コンストラクターを生成
|
190
|
+
|
191
|
+
var listView1 = new ListView(['Name', 'X', 'Y'], 'listView1', $('#dispListView1'));
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
listView1.appendRow(['Name%i%', '0', '0']);
|
196
|
+
|
197
|
+
listView1.setListViewEvent();
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
// 追加ボタンをクリックした場合
|
202
|
+
|
203
|
+
$('#addButton').click(function () {
|
204
|
+
|
205
|
+
listView1.appendRow(['Name%i%', '0', '0']);
|
206
|
+
|
207
|
+
listView1.setListViewEvent();
|
208
|
+
|
209
|
+
Calculate(listView1.getAllData(['name', 'x', 'y']));
|
210
|
+
|
211
|
+
dispSelectedPointDetail(listView1, 'pointer1', listView1.id, ['name', 'x', 'y']);
|
212
|
+
|
213
|
+
})
|
214
|
+
|
215
|
+
|
216
|
+
|
217
|
+
// 削除ボタンをクリックした場合
|
218
|
+
|
219
|
+
$('#delButton').click(function () {
|
220
|
+
|
221
|
+
listView1.removeRow(listView1.selectedRowData);
|
222
|
+
|
223
|
+
Calculate(listView1.getAllData(['name', 'x', 'y']));
|
224
|
+
|
225
|
+
dispSelectedPointDetail(listView1, 'pointer1', listView1.id, ['name', 'x', 'y']);
|
226
|
+
|
227
|
+
});
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
// 実行ボタンをクリックした場合
|
232
|
+
|
233
|
+
$('#actButton').click(function () {
|
234
|
+
|
235
|
+
Calculate(listView1.getAllData(['name', 'x', 'y']));
|
236
|
+
|
237
|
+
dispSelectedPointDetail(listView1, 'pointer1', listView1.id, ['name', 'x', 'y']);
|
238
|
+
|
239
|
+
});
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
// サブミットした場合
|
244
|
+
|
245
|
+
$('#listView1Form').submit(function () {
|
246
|
+
|
247
|
+
Calculate(listView1.getAllData(['name', 'x', 'y']));
|
248
|
+
|
249
|
+
dispSelectedPointDetail(listView1, 'pointer1', listView1.id, ['name', 'x', 'y']);
|
250
|
+
|
251
|
+
});
|
252
|
+
|
253
|
+
$('#listView2Form').submit(function () {
|
254
|
+
|
255
|
+
Calculate(listView1.getAllData(['name', 'x', 'y']));
|
256
|
+
|
257
|
+
dispSelectedPointDetail(listView1, 'pointer1', listView1.id, ['name', 'x', 'y']);
|
258
|
+
|
259
|
+
});
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
~省略~
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
});
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
~省略~
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
```
|
276
|
+
|
277
|
+
```JavaScript
|
278
|
+
|
279
|
+
*** list-view.js ***
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
var ListView = function (columns, id, selector) {
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
// 変数を定義
|
288
|
+
|
289
|
+
this.columns = columns;
|
290
|
+
|
291
|
+
this.id = id;
|
292
|
+
|
293
|
+
this.selector = selector;
|
294
|
+
|
295
|
+
this.selectedRowData;
|
296
|
+
|
297
|
+
this.selectedRowIndex = 0;
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
// メソッドを定義
|
302
|
+
|
303
|
+
this.appendRow = ListView.appendRow;
|
304
|
+
|
305
|
+
this.removeRow = ListView.removeRow;
|
306
|
+
|
307
|
+
this.getCellData = ListView.getCellData;
|
308
|
+
|
309
|
+
this.getAllData = ListView.getAllData;
|
310
|
+
|
311
|
+
this.setListViewEvent = ListView.setListViewEvent;
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
// ListViewを設置
|
316
|
+
|
317
|
+
ListView.setListView(columns, id, selector);
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
};
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
// *****************************************************************************
|
326
|
+
|
327
|
+
// ListViewを設置
|
328
|
+
|
329
|
+
// *****************************************************************************
|
330
|
+
|
331
|
+
ListView.setListView = function (columns, id, selector) {
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
var dom = '';
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
dom += '<table class="list-view" id="' + id + '">';
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
// ヘッダー行を生成
|
344
|
+
|
345
|
+
dom += '<tr class="-user-select-none">';
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
for (var i = 0; i < columns.length; i++) {
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
dom += '<th>' + columns[i] + '</th>';
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
}
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
dom += '</tr>';
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
dom += '</table>';
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
var template = _.template(dom);
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
selector.prepend(template());
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
}
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
// *****************************************************************************
|
382
|
+
|
383
|
+
// 行を追加
|
384
|
+
|
385
|
+
// *****************************************************************************
|
386
|
+
|
387
|
+
ListView.appendRow = function (defaultValues) {
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
var dom = '';
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
// 行数を定義
|
396
|
+
|
397
|
+
var rowLength = $('#' + this.id).children('tbody').children('[id=listViewRowData]').length;
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
// 行を追加
|
402
|
+
|
403
|
+
dom += '<tr id="listViewRowData">';
|
404
|
+
|
405
|
+
for (var i = 0; i < this.columns.length; i++) {
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
// テキストの初期値にパラメータをセット
|
410
|
+
|
411
|
+
var regExp = new RegExp('%i%', 'g');
|
412
|
+
|
413
|
+
var defaultValue = defaultValues[i].replace(regExp , rowLength);
|
414
|
+
|
415
|
+
|
416
|
+
|
417
|
+
dom += '<td>';
|
418
|
+
|
419
|
+
dom += '<input type="text" id="listViewColumnValue" value="' + defaultValue + '" spellcheck="false">';
|
420
|
+
|
421
|
+
dom += '</td>';
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
}
|
426
|
+
|
427
|
+
dom += '</tr>';
|
428
|
+
|
429
|
+
|
430
|
+
|
431
|
+
var template = _.template(dom);
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
$('#' + this.id).append(template());
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
// *****************************************************************************
|
444
|
+
|
445
|
+
// 選択した行を削除
|
446
|
+
|
447
|
+
// *****************************************************************************
|
448
|
+
|
449
|
+
ListView.removeRow = function (id) {
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
var parentThis = this;
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
id.remove();
|
458
|
+
|
459
|
+
|
460
|
+
|
461
|
+
$('#' + parentThis.id).children('tbody').children('[id=listViewRowData]').each(function (index, element) {
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
if (index == parentThis.selectedRowIndex) {
|
466
|
+
|
467
|
+
$(this).attr('class', 'selected');
|
468
|
+
|
469
|
+
parentThis.selectedRowData = $(this);
|
470
|
+
|
471
|
+
parentThis.selectedRowIndex = $('#' + parentThis.id + ' [id=listViewRowData]').index(this);
|
472
|
+
|
473
|
+
}
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
});
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
}
|
482
|
+
|
483
|
+
|
484
|
+
|
485
|
+
~省略~
|
486
|
+
|
487
|
+
|
488
|
+
|
489
|
+
// *****************************************************************************
|
490
|
+
|
491
|
+
// ListViewにイベントを設定
|
492
|
+
|
493
|
+
// *****************************************************************************
|
494
|
+
|
495
|
+
ListView.setListViewEvent = function () {
|
496
|
+
|
497
|
+
|
498
|
+
|
499
|
+
var parentThis = this;
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
$('#' + parentThis.id).children('tbody').children('[id=listViewRowData]').click(function () {
|
504
|
+
|
505
|
+
var clickThis = this;
|
506
|
+
|
507
|
+
$('#' + parentThis.id).children('tbody').children('[id=listViewRowData]').each(function (index, element) {
|
508
|
+
|
509
|
+
|
510
|
+
|
511
|
+
if (index != $('#' + parentThis.id).children('tbody').children('[id=listViewRowData]').index(clickThis)) {
|
512
|
+
|
513
|
+
$(element).attr('class', '');
|
514
|
+
|
515
|
+
}
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
});
|
520
|
+
|
521
|
+
$(this).attr('class', 'selected');
|
522
|
+
|
523
|
+
parentThis.selectedRowData = $(this);
|
524
|
+
|
525
|
+
parentThis.selectedRowIndex = $('#' + parentThis.id).children('tbody').children('[id=listViewRowData]').index(this);
|
526
|
+
|
527
|
+
});
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
}
|
532
|
+
|
533
|
+
```
|
1
実際の処理画面のURLを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -159,3 +159,9 @@
|
|
159
159
|
|
160
160
|
|
161
161
|
以上よろしくお願い致します。
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
実際の処理画面は以下URLにあります。
|
166
|
+
|
167
|
+
[座標計算 | Coordinate calculation](http://hogehogeago.xsrv.jp/sokuryou/coordinateCalculation.html)
|