<script>
$("#dropdownlist").kendoDropDownList({
dataSource: [
{ id:1, name: "Apples" },
{ id:2, name: "Oranges" }
],
dataTextField: "name",
dataValueField: "id"
});
var dropdownlist = $("#dropdownlist").data("kendoDropDownList");
var jsonStr = "";
for (var jx = 3; jx < 21; jx++)
{
jsonStr = '{ '
+ 'id : '
+ jx +
", "
+ 'name : '
+ '"blaaa_'+jx+ '"'
+ ' }';
dropdownlist.dataSource.add(jsonStr);
// give me an "undefined" not a fruit (no errors in console)
// console.log(jsonStr);
}
dropdownlist.dataSource.add({ id : 21, name : "Strawbeery" });
// works
</script>
为什么我不能在我的数据源中添加一个自创的 js 字符串?我虽然尝试过 var Myresult = JSON.parse(jsonStr);