我試圖實現電網的基本功能,在編譯時我的項目中,我得到一個錯誤說:「預期的對象」劍道UI電網基本實現
通過以下行代碼:
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
data: createRandomData(50), //exception in this line of code
pageSize: 10
},
你能幫我理解我需要寫的代替createRandomData嗎? 它是從哪裏獲取數據以將其放置在網格上的表名或它是其他內容? (順便說一句,我用作SQL Server 2008作爲後端,並在Visual Studio 2010 MVC4上運行此代碼),我也是MVC和Kendo UI的新手。
我想要實現事先使用MVC 4
由於從SQL Server中的數據綁定到網格! :)
下面的代碼:
<script>
$(document).ready(function() {
$("#grid").kendoGrid({
dataSource: {
data: createRandomData(50),
pageSize: 10
},
groupable: true,
sortable: true,
pageable: {
refresh: true,
pageSizes: true
},
columns: [{
field: "FirstName",
width: 90,
title: "First Name"
}, {
field: "LastName",
width: 90,
title: "Last Name"
}, {
width: 100,
field: "City"
}, {
field: "Title"
}, {
field: "BirthDate",
title: "Birth Date",
template: '#= kendo.toString(BirthDate,"dd MMMM yyyy") #'
}, {
width: 50,
field: "Age"
}
]
});
});
</script>
這裏的功能認定中:
function createRandomData(count) {
var data = [],
now = new Date();
for (var i = 0; i < count; i++) {
var firstName = firstNames[Math.floor(Math.random() * firstNames.length)],
lastName = lastNames[Math.floor(Math.random() * lastNames.length)],
city = cities[Math.floor(Math.random() * cities.length)],
title = titles[Math.floor(Math.random() * titles.length)],
birthDate = birthDates[Math.floor(Math.random() * birthDates.length)],
age = now.getFullYear() - birthDate.getFullYear();
data.push({
Id: i + 1,
FirstName: firstName,
LastName: lastName,
City: city,
Title: title,
BirthDate: birthDate,
Age: age
});
}
return data;
}
應控制器返回作爲計數傳遞的價值?
public ActionResult createRandomData()
{
return View();
}
它的匹配現在正確嗎? – subee 2013-02-26 06:09:12
你正在傳遞對象,沒有它..嘗試將該數據對象轉換成json – 2013-02-26 06:44:37