Add rows to table with jQuery .each and .append
up vote
0
down vote
favorite
I'm trying to add rows to a table. GetLogEntries returns an IEnumererable of an anonymous type. How to I refer to the members? When I append the constant string, the correct number of rows is written, but when I try to refer to an element in the anonymous type, nothing it written. How to I refer to the members of the anonymous type?
$.getJSON('@Url.Action("GetLogEntries")', { FacilityID: selectedFacility }, function (entries) {
if (entries != null && !jQuery.isEmptyObject(entries)) {
var logEntries = $('#logEntries');
$.each(entries, function (index, entry) {
//logEntries.append($("<tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>"));
logEntries.append($("<tr><td>",entry.InventoryID,"</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>"));
});
};
});
jquery
|
show 2 more comments
up vote
0
down vote
favorite
I'm trying to add rows to a table. GetLogEntries returns an IEnumererable of an anonymous type. How to I refer to the members? When I append the constant string, the correct number of rows is written, but when I try to refer to an element in the anonymous type, nothing it written. How to I refer to the members of the anonymous type?
$.getJSON('@Url.Action("GetLogEntries")', { FacilityID: selectedFacility }, function (entries) {
if (entries != null && !jQuery.isEmptyObject(entries)) {
var logEntries = $('#logEntries');
$.each(entries, function (index, entry) {
//logEntries.append($("<tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>"));
logEntries.append($("<tr><td>",entry.InventoryID,"</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>"));
});
};
});
jquery
1
Your append is weird. You are giving it the result of a$()
with three arguments, not one single string. Did you typo a comma in place of a+
concatenator?
– Taplar
Nov 9 at 20:23
1
$("<tr><td>",entry.InventoryID,"</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>")
doesn't make sense.
– Kevin B
Nov 9 at 20:24
@Taplar.append()
takes an infinite amount of elements, however the$( ... )
certainly doesn't make sense.
– Tyler Roper
Nov 9 at 20:24
1
.append in this case only gets one argument, i think taplar mispoke
– Kevin B
Nov 9 at 20:24
@Taplar & Kevin B - Yup, think we're all on the same page here. Clarified my comment.
– Tyler Roper
Nov 9 at 20:24
|
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm trying to add rows to a table. GetLogEntries returns an IEnumererable of an anonymous type. How to I refer to the members? When I append the constant string, the correct number of rows is written, but when I try to refer to an element in the anonymous type, nothing it written. How to I refer to the members of the anonymous type?
$.getJSON('@Url.Action("GetLogEntries")', { FacilityID: selectedFacility }, function (entries) {
if (entries != null && !jQuery.isEmptyObject(entries)) {
var logEntries = $('#logEntries');
$.each(entries, function (index, entry) {
//logEntries.append($("<tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>"));
logEntries.append($("<tr><td>",entry.InventoryID,"</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>"));
});
};
});
jquery
I'm trying to add rows to a table. GetLogEntries returns an IEnumererable of an anonymous type. How to I refer to the members? When I append the constant string, the correct number of rows is written, but when I try to refer to an element in the anonymous type, nothing it written. How to I refer to the members of the anonymous type?
$.getJSON('@Url.Action("GetLogEntries")', { FacilityID: selectedFacility }, function (entries) {
if (entries != null && !jQuery.isEmptyObject(entries)) {
var logEntries = $('#logEntries');
$.each(entries, function (index, entry) {
//logEntries.append($("<tr><td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>"));
logEntries.append($("<tr><td>",entry.InventoryID,"</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>"));
});
};
});
jquery
jquery
asked Nov 9 at 20:21
Barry Sweezey
11
11
1
Your append is weird. You are giving it the result of a$()
with three arguments, not one single string. Did you typo a comma in place of a+
concatenator?
– Taplar
Nov 9 at 20:23
1
$("<tr><td>",entry.InventoryID,"</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>")
doesn't make sense.
– Kevin B
Nov 9 at 20:24
@Taplar.append()
takes an infinite amount of elements, however the$( ... )
certainly doesn't make sense.
– Tyler Roper
Nov 9 at 20:24
1
.append in this case only gets one argument, i think taplar mispoke
– Kevin B
Nov 9 at 20:24
@Taplar & Kevin B - Yup, think we're all on the same page here. Clarified my comment.
– Tyler Roper
Nov 9 at 20:24
|
show 2 more comments
1
Your append is weird. You are giving it the result of a$()
with three arguments, not one single string. Did you typo a comma in place of a+
concatenator?
– Taplar
Nov 9 at 20:23
1
$("<tr><td>",entry.InventoryID,"</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>")
doesn't make sense.
– Kevin B
Nov 9 at 20:24
@Taplar.append()
takes an infinite amount of elements, however the$( ... )
certainly doesn't make sense.
– Tyler Roper
Nov 9 at 20:24
1
.append in this case only gets one argument, i think taplar mispoke
– Kevin B
Nov 9 at 20:24
@Taplar & Kevin B - Yup, think we're all on the same page here. Clarified my comment.
– Tyler Roper
Nov 9 at 20:24
1
1
Your append is weird. You are giving it the result of a
$()
with three arguments, not one single string. Did you typo a comma in place of a +
concatenator?– Taplar
Nov 9 at 20:23
Your append is weird. You are giving it the result of a
$()
with three arguments, not one single string. Did you typo a comma in place of a +
concatenator?– Taplar
Nov 9 at 20:23
1
1
$("<tr><td>",entry.InventoryID,"</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>")
doesn't make sense.– Kevin B
Nov 9 at 20:24
$("<tr><td>",entry.InventoryID,"</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>")
doesn't make sense.– Kevin B
Nov 9 at 20:24
@Taplar
.append()
takes an infinite amount of elements, however the $( ... )
certainly doesn't make sense.– Tyler Roper
Nov 9 at 20:24
@Taplar
.append()
takes an infinite amount of elements, however the $( ... )
certainly doesn't make sense.– Tyler Roper
Nov 9 at 20:24
1
1
.append in this case only gets one argument, i think taplar mispoke
– Kevin B
Nov 9 at 20:24
.append in this case only gets one argument, i think taplar mispoke
– Kevin B
Nov 9 at 20:24
@Taplar & Kevin B - Yup, think we're all on the same page here. Clarified my comment.
– Tyler Roper
Nov 9 at 20:24
@Taplar & Kevin B - Yup, think we're all on the same page here. Clarified my comment.
– Tyler Roper
Nov 9 at 20:24
|
show 2 more comments
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232796%2fadd-rows-to-table-with-jquery-each-and-append%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53232796%2fadd-rows-to-table-with-jquery-each-and-append%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Your append is weird. You are giving it the result of a
$()
with three arguments, not one single string. Did you typo a comma in place of a+
concatenator?– Taplar
Nov 9 at 20:23
1
$("<tr><td>",entry.InventoryID,"</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td><td>7</td></tr>")
doesn't make sense.– Kevin B
Nov 9 at 20:24
@Taplar
.append()
takes an infinite amount of elements, however the$( ... )
certainly doesn't make sense.– Tyler Roper
Nov 9 at 20:24
1
.append in this case only gets one argument, i think taplar mispoke
– Kevin B
Nov 9 at 20:24
@Taplar & Kevin B - Yup, think we're all on the same page here. Clarified my comment.
– Tyler Roper
Nov 9 at 20:24