getBlock (blockKey: String);
blockKey. Dashboard key.
The getBlock method returns dashboard block by its key.
There are two ways to get dashboard block key:
1. Select a block, switch to side panel title and hover over the block name with the cursor. A tooltip with block name and block key appears:
2. Get key of the desired block from metadata returned with the Kap.Dashboard.getMeta method.
To execute the example, the page must contain dashboard constructor named kapBox. A dashboard that contains one or more blocks must be open. The BODY tag must contain a DIV element with the "but" identifier. Add buttons clicking which will get key of the dashboard first block from metadata and show title of this block:
var mdButton = new PP.Ui.Button({ ParentNode: "but", Content: "First block key", Click: function () { var block = kapBox.getMeta().Md.kap.block.prop[2].area[0];//get object with first block key console.log(block);//output object with first block key to the console } }); var blockHeaderButton = new PP.Ui.Button({ ParentNode: "but", Content: "Show block title", Click: function () { var blockOne = kapBox.getBlock("BBAXG4TUGYEHU5E7");//get block by key blockOne.setBlockTitleVisible(True);//display block title } });
After executing the example the First Block Key and Show Block Title buttons are placed in the page. On clicking the First Block Key button the browser console displays a JSON object that contains properties of the first block, for example:
Object {@key: "BBAXG4TUGYEHU5E7", block: Object}
Clicking the Show Block Title shows title of the first block (key displayed to the console on clicking the First Block Key button must be set as a parameter of the getBlock method).
See also: