首页 新闻 搜索 专区 学院

Knockoutjs mapping插件如何绑定

0
悬赏园豆:30 [已关闭问题] 关闭于 2012-04-11 09:33

前台:

<script src="../../Scripts/jquery-1.4.4.js" type="text/javascript"></script>
<script src="../../Scripts/knockout.debug.js" type="text/javascript"></script>
<script src="../../Scripts/knockout.mapping-latest.debug.js" type="text/javascript"></script>
<div>
    --<p data-bind="text: Id">
    </p>
    <ul>
        <li></li>
    </ul>
</div>
<h2>
    Demo</h2>
<script type="text/javascript">
    var data = {};
    var viewModel = {};
    $(function () {
        $.getJSON("http://localhost:9299/Home/GetAllReps?q=" + new Date(), {}, function (r) { data = r; });
        ko.mapping.fromJS(data, viewModel);
    });

    ko.applyBindings(viewModel);
</script>

后台获取json的action:

        [HttpGet]
        public ActionResult GetAllReps()
        {
            var gustes = new Guest
            {
                Id = 11,
                Body = "KnockoutJs is a wonderful javascript",
                Subject = "Knockoutjs...",
                CreatTime = DateTime.Now.AddDays(-1)
            };


            return Json(gustes, JsonRequestBehavior.AllowGet);
        }

这样绑定运行不了,提示Id不能绑定,mapping插件改怎么正确的绑定呢?

Kratos Zhang的主页 Kratos Zhang | 初学一级 | 园豆:6
提问于:2012-04-10 18:58
< >
分享
所有回答(1)
0

欧呃

meepo3927 | 园豆:202 (菜鸟二级) | 2016-08-18 13:42
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册