数据绑定后 Telerik radgrid 的客户端绑定未更新

发布于 2024-11-29 10:42:07 字数 3832 浏览 0 评论 0原文

我正在尝试使用客户端 api 绑定 radgrid。

我对 javascript 函数 DoUpdate(sbiId) 发出调用,

function DoUpdate(sbiId) {
    var input = '{"SbiId":"' + sbiId+ '"}';
    var dataSource;

    $.ajax({ url: "http://localhost/Meta.WebService/DataService.svc/GetData",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        data: input,
        dataType: "json",
        success: function(data) {
            updateGrid(data);
        }
    });
}

function updateGrid(result) {
    var mtv = RadGridSprintBackLogItemDetailsInstance().get_masterTableView();
    mtv.set_dataSource(result);
    mtv.dataBind();
}

ajax 调用返回看似正确的 JSON 数据;这是每个提琴手的响应内容:

{"d":[{"_type":"SBIRevision:#Meta.Scrum","AssignedTo":"罗杰 Ng","ChangedBy":"Bob Hung","ChangedDate":"8/8/2011 3:48:31 PM","描述":"","状态":"未完成","标题":"火星单位 测试","WorkEstimate":"50","WorkRemaining":"50"},{"_type":"SBIRevision:#Meta.Scrum","AssignedTo":"Roger 吴”,“更改者”:“罗杰吴”,“更改日期”:“8/8/2011 5:12:46 PM","描述":"","状态":"进行中","标题":"火星单位 测试","WorkEstimate":"50","WorkRemaining":"50"},{"_type":"SBIRevision:#Meta.Scrum","AssignedTo":"Roger 吴”,“更改者”:“罗杰吴”,“更改日期”:“8/8/2011 5:13:39 PM","描述":"","状态":"进行中","标题":"火星单位 测试","WorkEstimate":"50","WorkRemaining":"50"},{"_type":"SBIRevision:#Meta.Scrum","AssignedTo":"Roger 吴”,“更改者”:“罗杰吴”,“更改日期”:“8/8/2011 5:14:25 PM","Description":"遇到...指向错误的版本 服务”,“状态”:“进行中”,“标题”:“火星单位 测试","WorkEstimate":"50","WorkRemaining":"50"},{"_type":"SBIRevision:#Meta.Scrum","AssignedTo":"Roger Ng","ChangedBy":"Bob Hung","ChangedDate":"8/10/2011 10:59:09 AM","描述":"遇到...指向错误的版本 服务”,“状态”:“进行中”,“标题”:“火星单位 测试","WorkEstimate":"50","WorkRemaining":"50"},{"_type":"SBIRevision:#Meta.Scrum","AssignedTo":"Roger 吴”,“更改者”:“罗杰吴”,“更改日期”:“8/11/2011 12:04:09 PM","Description":"遇到...指向错误的版本 服务”,“状态”:“完成”,“标题”:“火星单位 测试","WorkEstimate":"50","WorkRemaining":"50"}]}

这是我在aspx页面上声明我的radgrid的方式

<telerik:RadGrid runat="server" ID="RadGridSprintBackLogItemDetails" EnableViewState="false" EnableEmbeddedSkins="false" Skin="Meta">
    <MasterTableView AutoGenerateColumns="false" EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="true">
        <ItemStyle Wrap="false"></ItemStyle>
        <NoRecordsTemplate>
            <div style="margin-left: 5px;">
                Select a Sprint Backlog Item (SBI) from above to view its Revisions</div>
        </NoRecordsTemplate>
        <Columns>
            <telerik:GridBoundColumn DataField="ChangedDate" HeaderText="Changed Date">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Title" HeaderText="Title">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Description" HeaderText="Description">
            <ItemStyle Wrap="false"></ItemStyle>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="AssignedTo" HeaderText="Assigned To">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="WorkEstimate" HeaderText="Work Estimate">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="WorkRemaining" HeaderText="Work Remaining">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="State" HeaderText="State">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ChangedBy" HeaderText="Changed By">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

奇怪的是,在数据返回并绑定后,出现无记录模板。

I'm trying to bind a radgrid using the client side api.

I issue a call to javascript function DoUpdate(sbiId)

function DoUpdate(sbiId) {
    var input = '{"SbiId":"' + sbiId+ '"}';
    var dataSource;

    $.ajax({ url: "http://localhost/Meta.WebService/DataService.svc/GetData",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        data: input,
        dataType: "json",
        success: function(data) {
            updateGrid(data);
        }
    });
}

function updateGrid(result) {
    var mtv = RadGridSprintBackLogItemDetailsInstance().get_masterTableView();
    mtv.set_dataSource(result);
    mtv.dataBind();
}

The ajax call returns seemingly correct JSON data; here is the response content per fiddler:

{"d":[{"_type":"SBIRevision:#Meta.Scrum","AssignedTo":"Roger
Ng","ChangedBy":"Bob Hung","ChangedDate":"8/8/2011 3:48:31
PM","Description":"","State":"Not Done","Title":"MARS Unit
Tests","WorkEstimate":"50","WorkRemaining":"50"},{"
_type":"SBIRevision:#Meta.Scrum","AssignedTo":"Roger
Ng","ChangedBy":"Roger Ng","ChangedDate":"8/8/2011 5:12:46
PM","Description":"","State":"In Progress","Title":"MARS Unit
Tests","WorkEstimate":"50","WorkRemaining":"50"},{"_type":"SBIRevision:#Meta.Scrum","AssignedTo":"Roger
Ng","ChangedBy":"Roger Ng","ChangedDate":"8/8/2011 5:13:39
PM","Description":"","State":"In Progress","Title":"MARS Unit
Tests","WorkEstimate":"50","WorkRemaining":"50"},{"
_type":"SBIRevision:#Meta.Scrum","AssignedTo":"Roger
Ng","ChangedBy":"Roger Ng","ChangedDate":"8/8/2011 5:14:25
PM","Description":"Ran into...pointing to the wrong build
service","State":"In Progress","Title":"MARS Unit
Tests","WorkEstimate":"50","WorkRemaining":"50"},{"_type":"SBIRevision:#Meta.Scrum","AssignedTo":"Roger
Ng","ChangedBy":"Bob Hung","ChangedDate":"8/10/2011 10:59:09
AM","Description":"Ran into...pointing to the wrong build
service","State":"In Progress","Title":"MARS Unit
Tests","WorkEstimate":"50","WorkRemaining":"50"},{"
_type":"SBIRevision:#Meta.Scrum","AssignedTo":"Roger
Ng","ChangedBy":"Roger Ng","ChangedDate":"8/11/2011 12:04:09
PM","Description":"Ran into...pointing to the wrong build
service","State":"Done","Title":"MARS Unit
Tests","WorkEstimate":"50","WorkRemaining":"50"}]}

Here is how I declare my radgrid on the aspx page

<telerik:RadGrid runat="server" ID="RadGridSprintBackLogItemDetails" EnableViewState="false" EnableEmbeddedSkins="false" Skin="Meta">
    <MasterTableView AutoGenerateColumns="false" EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="true">
        <ItemStyle Wrap="false"></ItemStyle>
        <NoRecordsTemplate>
            <div style="margin-left: 5px;">
                Select a Sprint Backlog Item (SBI) from above to view its Revisions</div>
        </NoRecordsTemplate>
        <Columns>
            <telerik:GridBoundColumn DataField="ChangedDate" HeaderText="Changed Date">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Title" HeaderText="Title">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Description" HeaderText="Description">
            <ItemStyle Wrap="false"></ItemStyle>
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="AssignedTo" HeaderText="Assigned To">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="WorkEstimate" HeaderText="Work Estimate">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="WorkRemaining" HeaderText="Work Remaining">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="State" HeaderText="State">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ChangedBy" HeaderText="Changed By">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Oddly enough, after the data is returned and bound, the no records template appears.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夏の忆 2024-12-06 10:42:07

按如下方式更改 updateGrid 函数(使用 result.d 进行绑定):

function updateGrid(result) {
  var mtv = RadGridSprintBackLogItemDetailsInstance().get_masterTableView();
  mtv.set_dataSource(result.d);
  mtv.dataBind(); 
}

希望这会有所帮助。

Change your updateGrid function as follows (use result.d for binding):

function updateGrid(result) {
  var mtv = RadGridSprintBackLogItemDetailsInstance().get_masterTableView();
  mtv.set_dataSource(result.d);
  mtv.dataBind(); 
}

Hope, this helps.

↘紸啶 2024-12-06 10:42:07

当与 set_dataSource() 绑定时,您需要传递实际的数据对象数组。您获得的 jQuery 结果包含名为 .d 的字段中的数据数组。这就是您需要使用 result.d 的原因。

顺便说一句,您是否知道 RadGrid 可以自动绑定到 WCF Web 服务?请参阅 RadGrid 的 .NET 3.5 客户端数据绑定演示举个例子。服务设置是通过标记在 RadGrid 的定义中指定的。然后,RadGrid 自动连接到数据服务,检索结果并进行数据绑定。

When binding with set_dataSource(), you need to pass the actual array of data objects. The jQuery result you are getting contains the data array in a field named .d. This is why you need to use result.d.

On a side note, did you know that RadGrid can bind to WCF Web Services automatically? Refer to RadGrid's .NET 3.5 Client-Side DataBinding demo for a live example. Service settings are specified right in RadGrid's definition through the markup. RadGrid then automatically connects to the data service, retrieves the result and databinds.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文