简体   繁体   English

Typeprovider,websharper,f#,builiding order

[英]Typeproviders, websharper, f#, builiding order

So I have added some data using typeproviders into my applications ( github link ) So here is the problem. 所以我使用typeproviders将一些数据添加到我的应用程序中( github链接 )所以这就是问题所在。

1) What I wanted is that my Site.fs use data and build div according to rules I gave it. 1)我想要的是我的Site.fs使用数据并根据我给它的规则构建div。 Everything looks fine except.... 一切都很好看,除了....

I put back end calculation into WebSite project and probably because Web is startup project calculations in WebSite are never done and never pushed on database. 我把结束计算放回到WebSite项目中,可能是因为Web是WebSite中的启动项目计算从未完成过,也从未推送过数据库。 It is only displayed data which is already in database. 它只显示已存在于数据库中的数据。

Plus sometimes there is only ${title} and body instead of text provided in fsharp (even using default sitelet sample site). 另外,有时只有${title}和body而不是fsharp中提供的文本(即使使用默认的sitelet示例站点)。 Is that normal? 这是正常的吗? Restarting visual studio helps. 重启visual studio有帮助。

PS: sorry if my code doesn't look so spectacular I want it to work first and after that I will refactor it. PS:对不起,如果我的代码看起来不那么引人注目,我希望它首先工作,之后我会重构它。

As you guessed, top-level values (such as your Site.items ) are computed once at the launch of the application. 正如您猜测的那样,在应用程序启动时会计算一次顶级值(例如您的Site.items )。 If you want it to be computed at every page load, it needs to be computed inside the function that receives a Context<Action> . 如果您希望在每次加载页面时计算它,则需要在接收Context<Action>的函数内计算它。 [1] [1]

For example, you can do something like the following: 例如,您可以执行以下操作:

let getItems() =
    seq {
        for i in borkData.parseData.db.ONEPOST do
            yield [i.Title; i.Link; i.Poslodavac; i.MjestoRada; i.RokZaPrijavu]
    }

let JobsPage =
    Skin.WithTemplate "Jobs" <| fun ctx -> // this is the function that gets called for every page
        let items = getItems()
        [
            for i in items ->
                Div [Class "job"] -<
                  [
                    A [Class "title"] -< [HRef i.[1]] -< [ Text i.[0]]
                    P [Class "posted top"]  -< [ Text i.[3] ]
                    P [Class "employer"]  -< [ Text i.[2] ]
                  ]
        ]

Here, since getItems is a function, it computes its return value every time you ask for it with let items = getItems() . 这里,因为getItems是一个函数,所以每次你使用let items = getItems()求它时,它会计算它的返回值。


[1] You could also do it inside the function passed to Sitelet.Infer , if you used it. [1]您也可以在传递给Sitelet.Infer的函数内部执行此操作。如果您使用它,请执行此操作。 This would be useful if the Content you want to return depends on items , for example if you wanted to use a different template depending on items . 如果要返回的Content取决于items ,例如,如果您想根据items使用不同的模板,这将非常有用。

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

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