apsavin / bnsf

bem node single page application framework
MIT License
43 stars 4 forks source link

How can I render response to a custom block #26

Open jifeon opened 9 years ago

jifeon commented 9 years ago

Suppose I have a page with list of links, each link refers to concrete data which should be loaded by AJAX. I want to use bundled mechanism for blocks loading aka request-listener but do not want replace the whole page but specific block. How can I do it? You can give me a short answer and I will write an article to the wiki.

apsavin commented 9 years ago

I suppose, that you have a page, that must show different data, and that data depends on parameters of the route of the page, and this page have links to itself. If so, you can just add to your page bemtree declaration code like this:

js()({
    update: 'block-to-update'
})

or like this:

js()({
    update: {
        elem: 'elem-of-the-page-to-update'
    }
})

or like this:

js()({
    update: {
        block: 'some-block',
        elem: 'elem-of-some-block-to-update'
    }
})

You can pass an array of such declaration as value of update parameter also. If you want more precise control, you can create your-page.browser.js file and redefine methods from i-page.browser.js.