Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbd4abba

Browse files
committed
Update form_collections.rst
The variable collectionHolder must be assigned inside the jQuery ready function, but must be declared outside, since it is used also in other functions.I have put back the '$' in front of names of variables having jQuery objects as values and for uniformity, also added it to collectionHolder.
1 parentde2aac2 commitbd4abba

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

‎cookbook/form/form_collections.rst

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -358,27 +358,29 @@ will be show next):
358358

359359
..code-block::javascript
360360
361+
var $collectionHolder;
362+
361363
// setup an "add a tag" link
362-
var addTagLink=$('<a href="#">Add a tag</a>');
363-
var newLinkLi=$('<li></li>').append(addTagLink);
364+
var$addTagLink=$('<a href="#">Add a tag</a>');
365+
var$newLinkLi=$('<li></li>').append($addTagLink);
364366
365367
jQuery(document).ready(function() {
366368
// Get the ul that holds the collection of tags
367-
varcollectionHolder=$('ul.tags');
369+
$collectionHolder=$('ul.tags');
368370
369371
// add the "add a tag" anchor and li to the tags ul
370-
collectionHolder.append(newLinkLi);
372+
$collectionHolder.append($newLinkLi);
371373
372374
// count the current form inputs we have (e.g. 2), use that as the new
373375
// index when inserting a new item (e.g. 2)
374-
collectionHolder.data('index',collectionHolder.find(':input').length);
376+
$collectionHolder.data('index',$collectionHolder.find(':input').length);
375377
376-
addTagLink.on('click',function(e) {
378+
$addTagLink.on('click',function(e) {
377379
// prevent the link from creating a "#" on the URL
378380
e.preventDefault();
379381
380382
// add a new tag form (see next code block)
381-
addTagForm(collectionHolder, newLinkLi);
383+
addTagForm($collectionHolder,$newLinkLi);
382384
});
383385
});
384386
@@ -393,23 +395,23 @@ one example:
393395

394396
..code-block::javascript
395397
396-
functionaddTagForm(collectionHolder,newLinkLi) {
398+
functionaddTagForm($collectionHolder,$newLinkLi) {
397399
// Get the data-prototype explained earlier
398-
var prototype=collectionHolder.data('prototype');
400+
var prototype=$collectionHolder.data('prototype');
399401
400402
// get the new index
401-
var index=collectionHolder.data('index');
403+
var index=$collectionHolder.data('index');
402404
403405
// Replace '$$name$$' in the prototype's HTML to
404406
// instead be a number based on how many items we have
405407
var newForm=prototype.replace(/\$\$name\$\$/g, index);
406408
407409
// increase the index with one for the next item
408-
collectionHolder.data('index', index+1);
410+
$collectionHolder.data('index', index+1);
409411
410412
// Display the form in the page in an li, before the "Add a tag" link li
411-
var newFormLi=$('<li></li>').append(newForm);
412-
newLinkLi.before(newFormLi);
413+
var$newFormLi=$('<li></li>').append($newForm);
414+
$newLinkLi.before($newFormLi);
413415
}
414416
415417
..note::

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp