I am trying to order by the likes of an answer. I looked at the angular documentation for orderBy and it looks like I am following it. However, my table is not ordering by the likes for answer. Here is my html. If you want me to post more code let me know.
<div ng-controller="answerAndQuestionController">
<h1 ng-bind='question.question'></h1>
<h1 ng-bind='question.description'></h1>
<table>
<thead>
<tr>
<th>Answer</th>
<th>Description</th>
<th>User</th>
<th>Likes</th>
</tr>
</thead>
<tbody>
<tr ng-repeat = "answer in answers | orderBy:'answer.likes'">
<td><input ng-model = "answer.answer" readonly></td>
<td><input ng-model = "answer.description" readonly></td>
<td><input ng-model = "answer.user" readonly></td>
<td><input ng-model = "answer.likes" readonly>
<button ng-click = "like(answer.answer)" href="">like</button>
</td>
</tr>
</tbody>
</table>
</div>
If you check Angular's orderBy example you'll notice the analogy to define expression in orderBy without "object" (answer)
<tr ng-repeat = "answer in answers | orderBy:'likes'">
Related
<tr ng-repeat="item in groups">
<td hidden><input type="hidden" value="{{item.id_group}}" /></td>
<td><input type="text" value="{{item.description}}" class="form-control" /></td>
<td>
Edit |
Delete
</td>
</tr>
So this code was supposed to show values in a table and when the user changes anything in the description and click on Edit, it should POST the new value to the server. Instead it's posting the old value, I need some help please to identify why this is happening.
Try using Ng-model
<tr ng-repeat="item in groups track by $index">
<td hidden><input type="hidden" ng-model="groups[$index].id_group" /></td>
<td><input type="text" ng-model="groups[$index].description" class="form-control" /></td>
<td>
Edit |
Delete
</td>
</tr>
I am retrieving items from db put them in dir-paginate or ng-repeat what i am trying here to pass id in as model name to get key and name also as key as i am fetching a array to create many inputs and retrieve them in controller, but when i retrieve ng-model object values with console.log($scope.values); it says undefined.
how i will pass multiple generated inputs to controller in scope object is my question even ng-click dont work ??
view
<form angular-validator-submit="submitForm()"
name="submit-form" class="form-horizontal" novalidate
angular-validator>
<table>
<thead>
<tr>
<th>S.No</th>
<th>id</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr dir-paginate="x in items| itemsPerPage: pageSize" current-page="currentPage">
<td><input type="text" name="id" ng-model="values.{{x.id}}[$index]"></td>
<td><input type="text" name="test" ng-model="values.{{x.name}}[$index]"></td>
</tr>
</tbody>
</table>
<button type="submit" class="btn btn-primary">Save</button>
</form>
$scope.submitform = function(){
console.log($scope.values);
}
ng-model="values[x.id]" will do the work and define $scope.values = []; as suggested in comments.
AngularJs table is not working as expected.
I am trying to show the values of "sets" where it contains 10 values.
So what is want to do is that i want to create 10 rows, where it will show "set number" 1 to 10.
But it is displaying all the 10 values in a single rows, how i can make it 10 rows !!
<table st-table="rowCollection" class="table table-striped">
<thead>
<tr>
<th>Sets Number</th>
<th>Score of Sets 1</th>
<th>Score of Sets 2</th>
</tr>
</thead>
<tbody>
<tr>
{% for x in sets %}<td>{{ x }}</td>{% endfor %}
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
</tbody>
</table>
Which is looking like so --
You need to use the ng-repeat directive provided in angular as follows
<tr data-ng-repeat="x in sets">
<td> {{ x }} </td>
<td><input type="text"></td>
<td><input type="text"></td>
</tr>
You can follow the example on http://www.w3schools.com/angular/tryit.asp?filename=try_ng_repeat_array
DEMO: http://plnkr.co/edit/NHfCZ7FgcKGCNpIQVpfU?p=preview
How can I update multiple textbox in database using ASP.NET Web Pages(razor syntax). I want to edit emails of students. And the number of rows containing textbox varies or dynamic. Somebody help.
<tr>
<th>Name</th>
<th>Email</th>
</tr>
<tr>
<td>Jason</td>
<td><input type="text" name="txtbox1"></td>
</tr>
<tr>
<td>Kripkee</td>
<td><input type="text" name="txtbox2"></td>
</tr>
<tr>
<td>Kane</td>
<td><input type="text" name="txtbox3"></td>
</tr>
<tr>
<td>Michael</td>
<td><input type="text" name="txtbox4"></td>
</tr>
<tr>
<td><input type="submit" value="Update"></td>
</tr>
</table>
</form>
You can try this:
Assuming you have a view model providing a list of students.
View -
#foreach (var student in Model.Students)
{
<tr>
<td>#student.Name</td>
<td><input name="studentEmails[#student.Id]"/></td>
</tr>
}
Controller -
public ActionResult UpdateEmails(IDictionary<int, string> studentEmails)
I have a form on my cfm page, that is to insert a new row into an SQL datasource. The cfm page hosts the form - and when submitted the -action.cfm page inserts the data and relocates the user to a page listing the new information. The problem I am getting is when I submit the form I am getting:: Element NEWUSERID is undefined in FORM.
the form on the insertScores.cfm page:
<form method="post" action="insertScores-action.cfm">
<table>
<tr>
<td>User ID</td>
<td><input name="newUserID" type = "text" size = "50"></td>
</tr>
<tr>
<td>First Name</td>
<td><input name="newFirstName" type="text" size="50"></td>
</tr>
<tr>
<td>Last Name</td>
<td><input name="newLastName" type="text" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td><input name="newEmailAdd" type="text" size="50"></td>
</tr>
<tr>
<td>Score</td>
<td><input name="newScore" type="text" size="50"></td>
</tr>
<tr>
<td>Pass Date</td>
<td><input name="newPassDate" type="text" size="50" value="dd/mm/yyyy"></td>
</tr>
<tr>
<td>Level</td>
<td><input name="newLevel" type="text" size="50"></td>
</tr>
<tr>
<td><input type="submit" value="Insert Scores"></td>
</tr>
</table>
The insertScores-action.cfm page
<cfquery name="insertScores" datasource="staffwrite">
INSERT INTO protinfo_scores (
userID
, first_name
, last_name
, email
, curr_score
, curr_score_date
, level
)
VALUES (
'#form.newUserID#'
, '#form.newFirstName#'
, '#form.newLastName#'
, '#form.newEmailAdd#'
, '#form.newScore#'
, '#form.newPassDate#'
, '#form.newLevel#'
)
</cfquery>
<cfquery name = "queryScore" datasource="staff">
SELECT userid, level
FROM protinfo_scores
WHERE userid LIKE '#form.newUserid#'
AND level = '#form.newLevel#'
</cfquery>
<cflocation URL="newScore.cfm?userid=#url.userid#&level=#url.level#">
newScore.cfm
<center>
<h2>Your ammendments have been made.</h2><hr>
</center>
<cfquery name = "queryScore" datasource="staff">
SELECT first_name, last_name, email, curr_score, curr_score_date, userid, level
FROM protinfo_scores
WHERE userid LIKE '#URL.userid#'
AND level = #URL.level#
</cfquery>
<cfoutput query="queryScore">
<table>
<tr bgcolor=beige>
<td>Name</td>
<td width="40">#queryScore.first_name# #queryScore.last_name#</td>
</tr>
<tr>
<td>Email</td>
<td width="40">#queryScore.email#</td>
</tr>
<tr bgcolor=beige>
<td>Username</td>
<td width="100">#queryScore.userid#</td>
</tr>
<tr>
<td>Level</td>
<td width="100">#queryScore.level#</td>
</tr>
<tr bgcolor=beige>
<td>Current Score</td>
<td width="40">#queryScore.curr_score#</td>
</tr>
<tr>
<td>Date Passed</td>
<td width="40">#queryScore.curr_Score_date#</td>
</tr>
</table>
</cfoutput>
and when submitted the -action.cfm page inserts the data and relocates
the user to a page listing the new information
I can't tell from the wording if this is the desired effect or the actual effect. If it is the actual effect, your error is occurring on newScore.cfm which would make sense because the data in the form scope does not persist after the cflocation and you're trying to use form.newUserID after the output table..
If this is the desired effect and NOT the actual effect...
As Dan said, you're looking at two different files. You show code from insertScores-application.cfm but your action is pointing to insertScores-action.cfm.
The code in your question is not exact copy/paste or even all of your code (you're missing a </form> tag to say the least). In this case I'd suggest showing us the actual code AND the error message. Many times I see element XXX is undefined in FROM (notice it says FROM and not FORM, something easy to miss when you're staring at the same thing for hours). The error message will tell you what line number the error is on. Is the line number actually among the code you posted?
I changed my <form></form> to a <cfform></cfform> and all now appears to work swimmingly. I was under the impression this would not make any difference but clearly it does.