【问题标题】:Fetch data with SmartClient LGPL version使用 SmartClient LGPL 版本获取数据
【发布时间】:2015-06-03 12:13:42
【问题描述】:

我想使用 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>

【问题讨论】:

    标签: smartclient


    【解决方案1】:

    好的,我找到了解决方案。线索是使用 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"} 
        ]
      }
    }
    

    【讨论】:

      【解决方案2】:

      您要做的是为其他操作定义 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()"});
      

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

      我希望这会有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-18
        • 2022-01-01
        • 2017-04-28
        • 2019-09-29
        • 1970-01-01
        • 2019-12-24
        相关资源
        最近更新 更多