简体   繁体   English

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

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

I am a begginner in Seaside.我是Seaside的初学者。

I have a table (like a spreadsheet) made using html in Pharo 4.0 Seaside, that takes data from a PostgreSQL DB using the Garage driver for Seaside.我在 Pharo 4.0 Seaside 中有一个使用 html 制作的表格(如电子表格),该表格使用 Seaside 的 Garage 驱动程序从 PostgreSQL DB 获取数据。

I put contenteditable=true to the tableData and I can modify it, but it does not update the entry in the database.我将contenteditable=true放到 tableData 中,我可以修改它,但它不会更新数据库中的条目。

I do not want to use a form that gets the data and then runs a query once I click submit, I just want to modify the spreadsheet cell (the html tabledata tag) and then when I press enter (or I just take the mouse off the cell) I want to run a Query that updates the database.我不想使用获取数据然后单击提交后运行查询的表单,我只想修改电子表格单元格(html tabledata 标记)然后当我按下回车键时(或者我只是把鼠标移开单元格)我想运行一个更新数据库的查询。

I tried using jQuery and Ajax but I can't make it work.我尝试使用 jQuery 和 Ajax 但我无法使其工作。 I am not able to get the data that I entered and the data that describes the cell so I can run a Query.我无法获取我输入的数据和描述单元格的数据,因此我可以运行查询。

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.

The question is ambiguous, because it is not strictly Seaside related but more related with the architecture of your application, in particular persistence.这个问题是模棱两可的,因为它不是严格意义上的 Seaside 相关,而是更多地与您的应用程序的架构相关,特别是持久性。

A few questions...几个问题...

  • What #insertOrUpdateEntryWithCode:withName:forDay:month:year: does and return? #insertOrUpdateEntryWithCode:withName:forDay:month:year:做什么并返回?
  • How do you get access to a database connection?如何访问数据库连接? (global pool or your Seaside session?) (全局池还是你的Seaside session?)

Also, you're using an old version of Pharo probably with an old version of Seaside, and if PostgreSQL connection is required, I'd avise you to use the P3 driver .此外,您使用的旧版本的 Pharo 可能与旧版本的 Seaside 一起使用,如果需要 PostgreSQL 连接,我建议您使用P3 驱动程序

Then try this:然后试试这个:

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

You'll have to sanitize the content of html submitted, since a newline is going to be converted to <br> , which if submitted again will be converted to &lt;br&gt;您必须清理 html 提交的内容,因为换行符将转换为<br> ,如果再次提交将转换为&lt;br&gt; , etc. , ETC。

atRow:column returns the value and atRow:column:put: sets it. atRow:column返回值并atRow:column:put:设置它。 I used an array of arrays to hold the results.我使用了一个 arrays 数组来保存结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM