我是asp.net MVC开发人员。
在我的模型中,
public class GiftModel
{
public string Title { get; set; }
public double Price { get; set; }
}controller=>
public ActionResult Test()
{
ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
GiftModel[] initialState = new[] {
new GiftModel { Title = "Tall Hat", Price = 49.95 },
new GiftModel { Title = "Long Cloak", Price = 78.25 }
};
return View(initialState);
}但是当我在脚本中执行时,
initialValues= ""{\"Title\":\"Tall Hat...ak\",\“价格\”:78.25}“”
var result = ko.observable(initialValues)此输出无结果
发布于 2013-08-30 16:49:23
据我所知,您需要创建一个observableArray,但问题是您的initialValues是一个字符串。您需要使用JSON.parse将字符串转换为对象
initialValues= JSON.parse("[{\"Title\":\"Tall Hat...ak\",\"Price\":78.25}]");
var result = ko.observableArray(initialValues)https://stackoverflow.com/questions/18528378
复制相似问题