0

我想使用 LGPL 版本的智能客户端连接到我自己的服务器。我希望 SmartClient 发送一个获取请求(包含操作类型、范围等)——我会处理其余的。但我不能强迫 SmartClient 这样做。我所能做的就是强制它发送一个简单的 GET 请求。我应该添加什么?

我的代码:

    <HTML>
    <HEAD>
    <SCRIPT>var isomorphicDir="../isomorphic/";</SCRIPT>
    <SCRIPT SRC=../isomorphic/system/modules/ISC_Core.js></SCRIPT>
    <SCRIPT SRC=../isomorphic/system/modules/ISC_Foundation.js></SCRIPT>
    <SCRIPT SRC=../isomorphic/system/modules/ISC_Containers.js></SCRIPT>
    <SCRIPT SRC=../isomorphic/system/modules/ISC_Grids.js></SCRIPT>
    <SCRIPT SRC=../isomorphic/system/modules/ISC_Forms.js></SCRIPT>
    <SCRIPT SRC=../isomorphic/system/modules/ISC_DataBinding.js></SCRIPT>
    <SCRIPT SRC=../isomorphic/skins/SmartClient/load_skin.js></SCRIPT>
    </HEAD>
    <BODY>
    <SCRIPT>

    isc.DataSource.create({
        ID:"countries",
        dataURL:"countries_small.js",
        fields:[
            {name:"name", type:"text", primaryKey:true},
            {name:"population"},
        ]
    });

    isc.ListGrid.create({
        width: "100%",
        height: 50,

        dataSource: "countries",
        drawAllMaxCells:0,
        dataPageSize:1,
        drawAheadRatio:1,
        showAllRecords:false,
        autoFetchData: true
    });

    </SCRIPT>
    </BODY>
    </HTML>
4

2 回答 2

2

好的,我找到了解决方案。线索是使用 RestDataSource。

isc.RestDataSource.create({
    ID:"countriesDS",
    dataFormat:"json",
    dataURL: "partial.js",
    operationBindings:[
                       {operationType:"fetch", dataProtocol:"postParams"}
                    ],
   fields:[
           {title:"Name", name:"name", type:"text", primaryKey:true},
           {title:"Population", name:"population", type:"text"}
       ]
});

isc.ListGrid.create({
    width: "100%",
    height: 60,
    dataFetchMode:"paged",
    dataSource: "countriesDS",
    dataPageSize:2,
    canEdit:true,
    drawAheadRatio:1,
    showAllRecords:false,    
    autoFetchData: true
});

然后,响应可能如下所示:

{ response:{
    status:0,
    startRow:0,
    endRow:1,
    totalRows:2,
    data:[
          {name:"Italy", population:"12"},
          {name:"Germany", population:"121"} 
    ]
  }
}
于 2012-06-08T22:35:41.747 回答
0

您要做的是为其他操作定义 URL:

将 dataSource 对象中的 dataURL 替换为单独的绑定:

operationBindings:[  
{operationType:"fetch", dataURL:"<fetch URL>"},
{operationType:"add",dataProtocol:"postParams",  dataURL:"<insert URL>"},
{operationType:"update",dataProtocol:"postParams", dataURL:"<Update URL>"},
{operationType:"remove",dataProtocol:"postParams", dataURL:"<delete URL>"}]

设置网格 ID 并使其可编辑:

ID:"MyGrid"
canEdit: true,
editEvent: "click"

当您移出该行时,它应该触发更新请求。

使用以下命令为新行添加按钮和删除行:

isc.IButton.create({title:"New",click:"MyGrid.startEditingNew()"});
isc.IButton.create({title:"Delete",click:"MyGrid.removeData()"});

移出该行后,您的添加 URL 应该会收到请求。按下按钮后删除。

我希望这会有所帮助。

于 2012-03-15T11:22:38.797 回答