Pharo Seaside - 如何在 html 中编辑标签后更新数据库条目

Pharo Seaside - How to update a Database entry after editing a tag in html

我是海边小白

我在 Pharo 4.0 Seaside 中使用 html 制作了一个 table(类似于电子表格),它使用 Seaside 的 Garage 驱动程序从 PostgreSQL 数据库获取数据。

我将 contenteditable=true 放入 table 数据中,我可以修改它,但它不会更新数据库中的条目。

我不想使用获取数据的表单,然后在单击提交后 运行 进行查询,我只想修改电子表格单元格(html tabledata 标签),然后当我按下回车键(或者我只是将鼠标从单元格上移开)时,我想 运行 一个更新数据库的查询。

我试过使用 jQuery 和 Ajax,但无法正常工作。我无法获取输入的数据和描述单元格的数据,因此我无法 运行 查询。

html tableData 
attributeAt: 'contenteditable' put: 'true'; 
onClick: (html jQuery this addClass:'clicked'); 
onBlur:(self insertOrUpdateEntryWithCode: ((html jQuery this)html) withName: name forDay: day month:month year:year); 
with: value.

这个问题是模棱两可的,因为它不是严格意义上的 Seaside 相关,而是与您的应用程序的架构相关,尤其是持久性。

几个问题...

  • #insertOrUpdateEntryWithCode:withName:forDay:month:year: 和 return 做什么?
  • 如何访问数据库连接? (全局池还是您的 Seaside session?)

此外,您使用的是旧版本的 Pharo,可能与旧版本的 Seaside 一起使用,如果需要 PostgreSQL 连接,我建议您使用 P3 driver.

然后试试这个:

renderContentOn: html
  html
    table: [ 1 to: 10 do: [ :rowIndex | 
       html tableRow: [ 1 to: 5 do:
         [ :colIndex | self renderCellAtRow: rowIndex column: colIndex on: html ] ] ] ]
renderCellAtRow: rowIndex column: colIndex on: html
    ^ html tableData
        attributeAt: 'contenteditable' put: 'true';
        id: (self cellIdRow: rowIndex col: colIndex);
        onBlur:
            (html jQuery ajax
                callback: [ :v | self atRow: rowIndex column: colIndex put: v ]
                    value: html jQuery this html;
                onComplete:
                    ((html jQuery id: (self cellIdRow: rowIndex col: colIndex)) load
                        html: [ :h | h render: (self atRow: rowIndex column: colIndex) ]));
        with: (self atRow: rowIndex column: colIndex)
cellIdRow: rowIndex col: colIndex
    ^ 'r<1p>c<2p>' expandMacrosWith: rowIndex with: colIndex

您必须清理提交的 html 的内容,因为换行符将被转换为 <br>,如果再次提交将被转换为 &lt;br&gt;,等等

atRow:column returns 值和 atRow:column:put: 设置它。我使用了一个数组数组来保存结果。