煤矸石空心砖

新闻分类

联系我们Contact

企业名称:桐城市南口新型建材有限公司

联系人:崔经理

电话:0556-6568069

手机:18156911555

邮箱:303927413@qq.com

地址:桐城市龙腾街道高桥村

网址:   www.nkxxjc.com 



您的当前位置: 首 页 > get query params from url > Router Map a Controller's Property to a Different Query Param Key

Router Map a Controller's Property to a Different Query Param Key

发布日期:2022-09-28 11:54 作者: 点击:

Router Map a Controller's Property to a Different Query Param Key Advertisements Previous Page Next Page  

The controller has a default query parameter property which attaches a query parameter key to it and maps a controller property to a different query parameter key.

Syntax Ember.Controller.extend ({ queryParams: { queryParamName: "Values" }, queryParamName: null }); Example

The example given below shows mapping a controller's property to a different query param key. Create a new route and name it as parammapcontrol and open the router.js file to define URL mappings −

import Ember from 'ember'; //Access to Ember.js library as variable Ember import config from './config/environment'; //It provides access to app's configuration data as variable config //The const declares read only variable const Router = Ember.Router.extend ({ location: config.locationType, rootURL: config.rootURL }); //Defines URL mappings that takes parameter as an object to create the routes Router.map(function() { this.route('parammapcontrol'); }); //It specifies Router variable available to other parts of the app export default Router;

Open the file application.hbs file created under app/templates/ with the following code −

Map a Controller's Property {{#link-to 'parammapcontrol'}}Click Here{{/link-to}}

When you click the above link, the page should open with an input box which takes a value entered by an user. Open the parammapcontrol.hbs file and add the following code −

//sending action to the addQuery method {{input value = queryParam}} {{outlet}}

Now open the parammapcontrol.js file created under app/controllers/ with the following code −

import Ember from 'ember'; export default Ember.Controller.extend ({ queryParams: [{ //mapping the string 'querystring' of the 'query's' query parameter query: "querystring" }], //initialy query's 'query parameter' will be null query: null, queryParam: Ember.computed.oneWay('query'), actions: { addQuery: function () { this.set('query', this.get('queryParam')); document.write(this.get('query')); } } }); Output

Run the ember server and you will receive the following output −

Ember.js Router Map Controllers Property

When you click on the link, it will generate an input box wherein you can enter a value. This will send an action to the addQuery method −

Ember.js Router Map Controllers Property

After clicking the button, it will show the parameter value to the right of the "?" in a URL −

Ember.js Router Map Controllers Property emberjs_router.htm Previous Page Print Page Next Page   Advertisements

本文网址:

关键词:get query params from url