Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

what can I do if JSLint complains about "i" being an unused variable in such a scenario:

var items = "<option selected></option>";
$.each(data, function (i, item) {
    items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
});

(i, item) is the required order of parameters and I'm only using "item".

Is there any other solution than tolerating unused variables or rewriting the $.each to use the index, both solutions which I would prefer not to do?

Thanks in advance.

Update: I appreciate all the suggestions but this code is simply an example to show you what I mean and I'm interested to see a general solution, if there's any. Thanks.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
346 views
Welcome To Ask or Share your Answers For Others

1 Answer

Try:

var items = "<option selected></option>";
/*jslint unparam: true*/
$.each(data, function (i, item) {
    items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
});
/*jslint unparam: false*/  // so that you still get warnings from other functions

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...