开发者

ASP.NET AJAX DataContext object not tracking changes on nested complex types

开发者 https://www.devze.com 2022-12-27 13:33 出处:网络
I\'ve been struggling for ages now to get the ASP.NET AJAX DataContext object to track my changes to complex types.The binding seems to work and the underlying object gets updated, but the DataContext

I've been struggling for ages now to get the ASP.NET AJAX DataContext object to track my changes to complex types. The binding seems to work and the underlying object gets updated, but the DataContext object does not track the change.

Here is a simplified version of my code (with the WCF fetch and save call taken out).

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml" >  
<head>  
<title></title>  
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/beta/0911/Start.js"></script>  
<script type="text/javascript">
    var customers = null;
    var dataContext = null;

    Sys.require([Sys.components.dataView, Sys.components.dataContext], function() {

        customers =
        [
            { Contact: { Name: 'Fred Johnson' }, Country: { Name: 'USA'} },
            { Contact: { Name: 'Davie Jones' }, Country: { Name: 'England'} }
        ];

        dataContext = Sys.create.dataContext();
        dataContext.trackData(customers);

        Sys.create.dataView('#CustomerView',
        {
            data: customers
        });
    });

    function onSave() {
        if (dataContext.get_hasChanges()) {
            alert("Saved");
        }
        else {
            alert("No changes to save.");
        }
    }

    </script>  
</head>  
<body xmlns:sys="javascript:Sys">  
    <div id="CustomerView" class="sys-template">  
        <ul>  
            <li>
                <label for="country">{{Contact.Name}}</label>
                <input id="country" sys:value="{binding Country.Name}" />
            </li>  
        开发者_如何学编程</ul>  
    </div>  
    <input id="save" type="button" value="Save" onclick="javascript: onSave();" />
</body>  
</html>

Why when I click the save button, having changed the value in the country text box, the dataContext object thinks that there are no changes to save?


How about adding Sys.Observer.makeObservable(customers )

0

精彩评论

暂无评论...
验证码 换一张
取 消