Knockout can be used to obtain array element indexes. It is implemented in MVC. knockoutmvc
When traversing arrays and sets, you usually need to obtain the element index. In this article, you can use two methods to obtain the index using Knockout.
Suppose there is a model like this:
namespace UseIndex.Models{ public class Student { public int Id { get; set; } public string Name { get; set; } }}
In HomeController, simulate a collection of Student, project the set of Name attributes, and return it to the foreground view in Json format.
Using System. collections. generic; using System. linq; using System. web. mvc; using UseIndex. models; namespace UseIndex. controllers {public class HomeController: Controller {public ActionResult Index () {return View ();} public JsonResult GetStudentNames () {var students = new List <Student> () {new Student () {Id = 1, Name = "Xiao Ming"}, new Student () {Id = 2, Name = "Xiao Tian "}}; var names = from student in students select new {student. name}; return Json (names, JsonRequestBehavior. allowGet );}}}
In Home/Index. cshtml:
@ {Layout = null ;}<! DOCTYPE html>
Above, $ data refers to the current set element. $ Root indicates the ViewModel in the root context.
Run:
Summary
There are two ways to obtain the index of a set or array element:
1. data-bind = "text: $ index" or data-bind = "text: $ index () + 1"
2. In View Model, obtain the context first, and then context. $ index ()
Js to obtain the string index of array elements ,~
Var array = new Array ();
Array [0] = "1 ";
Array [1] = "2 ";
Array [2] = "3 ";
Var index = array. length;
For (var I = 0; I <index; I ++ ){
Document. writeln (the index of array [I] + "is:" + I );
}
Write a java program, copy the elements in index location 03 of array arr1 to array arr2, and output the arr1 and arr2 elements,
Is there a red line under the word copyOf, and the system prompts that this method is not defined?
-|
I heard people say: Eclipse does not come with this method, which is available in JDK 1.6.0.
So, check whether JDK6.0 is installed and you use it.