我是新來的JavaScript .... 我在數據庫中的數據...... 我使用LINQ如下JSON在MVC4使用javascript
public List<SelectListItem> getTokens()
{
var tokens = from T in db.tokens select T;
List<SelectListItem> items = new List<SelectListItem>();
foreach (var t in tokens)
{
items.Add(new SelectListItem { Value = t.id.ToString(), Text = t.tname });
}
return items.ToList<SelectListItem>;
}
或者
public string getTokens()
{
var tokens = from T in db.tokens select T;
string s = "[";
foreach (var t in tokens)
{
s += "{ id:" + t.id.ToString() + ", name: " + t.tname + "},";
}
s += "]";
return s;
}
得到它
我想這個字符串/列表傳遞給我的JS功能這樣的事情...
$(document).ready(function() {
$("#demo-theme").tokenInput([
{ id: 7, name: "Ruby" },
{ id: 11, name: "Python" },
{ id: 13, name: "JavaScript" },
{ id: 17, name: "ActionScript" },
{ id: 19, name: "Scheme" },
{ id: 23, name: "Lisp" },
{ id: 29, name: "C#" },
{ id: 31, name: "Fortran" },
{ id: 37, name: "Visual Basic" },
{ id: 41, name: "C" },
{ id: 43, name: "C++" },
{ id: 47, name: "Java" }],
{theme: "ab"
});
});
我需要t替換他與我的字符串/列表... 或任何其他的方式來傳遞項目的第一個列表....
謝謝.....那個的Javascript也需要幫助 – pavan