I want to call a variable dynamically.
export class AppComponent {
my_a_variable = 'test a';
my_b_variable = 'test b';
type = 'a'; // this variable value will come from another place dynamically.
}
In my html i need something like
<div>{{my_{{type}}_variable}}</div>
I know it can be solved with an assoc array but I can't use this here.
Can you please help?
Thanks.
Hope this works,
export class AppComponent {
my_a_variable = 'test a';
my_b_variable = 'test b';
type = 'a';
}
In your template you can do like this,
<div>{{this['my_' + type + '_variable']}}</div>
Related
Is it possible to find the count of items in a Typescript record?
For example something like
const testRecord: Record<string, string> = {
'one': 'value1',
'two': 'value2'
};
var length = testRecord.length;
// looking for length to be 2 but is undefined as there is no length property
For reference: https://www.typescriptlang.org/docs/handbook/utility-types.html#recordkt
I've just found this answer here for the length of a javascript object which seems to work just fine:
Length of a JavaScript object
My implementation to answer the example above was:
const testRecord: Record<string, string> = {
'one': 'value1',
'two': 'value2'
};
var length: Object.keys(testRecord).length;
// length equals 2
However please let me know if there is a better, more specific "Record" way to do this?
Maybe it's not what you wanted, but there is a Map type that has size property.
You can use it like this:
let m = new Map<string, any>();
m.set('a', 1)
let one = m.get('a');
console.log('a value is: ' + one + '; size of the map is: ' + m.size);
Map doesn't work exactly as Object does, so take a look at differences in behaviour first: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map#objects_vs._maps
I am modifying the SalesConfirmDP class and trying to add the CustVendExternalItem.ExternalItemTxt field into a new field I have created.
I have tried a couple of things but I do not think my syntax was correct i.e I declare the CustVendExternalItem table in the class declaration. But then when I try to insert CustVendExternalItem.ExternalItemTxt into my new field, it does not populate, I guess there must be a method which I need to include?
If anyone has any suggestion it would be highly appreciated.
Thank you in advance.
private void setSalesConfirmDetailsTmp(NoYes _confirmTransOrTaxTrans)
{
DocuRefSearch docuRefSearch;
// Body
salesConfirmTmp.JournalRecId = custConfirmJour.RecId;
if(_confirmTransOrTaxTrans == NoYes::Yes)
{
if (printLineHeader)
{
salesConfirmTmp.LineHeader = custConfirmTrans.LineHeader;
}
else
{
salesConfirmTmp.LineHeader = '';
}
salesConfirmTmp.ItemId = this.itemId();
salesConfirmTmp.Name = custConfirmTrans.Name;
salesConfirmTmp.Qty = custConfirmTrans.Qty;
salesConfirmTmp.SalesUnitTxt = custConfirmTrans.salesUnitTxt();
salesConfirmTmp.SalesPrice = custConfirmTrans.SalesPrice;
salesConfirmTmp.DlvDate = custConfirmTrans.DlvDate;
salesConfirmTmp.DiscPercent = custConfirmTrans.DiscPercent;
salesConfirmTmp.DiscAmount = custConfirmTrans.DiscAmount;
salesConfirmTmp.LineAmount = custConfirmTrans.LineAmount;
salesConfirmTmp.CurrencyCode = custConfirmJour.CurrencyCode;
salesConfirmTmp.PrintCode = custConfirmTrans.TaxWriteCode;
if (pdsCWEnabled)
{
salesConfirmTmp.PdsCWUnitId = custConfirmTrans.pdsCWUnitId();
salesConfirmTmp.PdsCWQty = custConfirmTrans.PdsCWQty;
}
**salesConfirmTmp.ExternalItemText = CustVendExternalItem.ExternalItemTxt;**
if ((custFormletterDocument.DocuOnConfirm == DocuOnFormular::Line)
|| (custFormletterDocument.DocuOnConfirm == DocuOnFormular::All))
{
docuRefSearch = DocuRefSearch::newTypeIdAndRestriction(custConfirmTrans,
custFormletterDocument.DocuTypeConfirm,
DocuRestriction::External);
salesConfirmTmp.Notes = Docu::concatDocuRefNotes(docuRefSearch);
}
salesConfirmTmp.InventDimPrint = this.printDimHistory();
Well, AX cannot guess which record you need, there is a helper class CustVendExternalItemDescription to deal with it:
boolean found;
str externalItemId;
...
[found, externalItemId, salesConfirmTmp.ExternalItemText] = CustVendExternalItemDescription::findExternalItemDescription(
ModuleCustVend::Cust,
custConfirmTrans.ItemId,
custConfirmTrans.inventDim(),
custConfirmJour.OrderAccount,
CustTable::find(custConfirmJour.OrderAccount).CustItemGroupId);
The findExternalItemDescription method returns more information than you need here, but you have to define variables to store it anyway.
Well, the steps to solve this problem are fairly easy and i will try to give you a step by step approach how to solve this problem.
1) Are you initialising CustVendExternalItem properly? Make a record of the same and initialise it as Jan has shown above, then debug your code and see if the value is being initialised in your DP class.
2)If your value is being initialised correctly, but it is not showing up in the report design there can be multiple issues such as:
Overlapping of text boxes.
Insufficient space for the given field
Some report parameter/property not being set correctly which causes
your value not to show up on the report.
Check these one by one and you should end up arriving towards a solution
I have written down trigger in Salesforce APEX . It is working properly.
Code For Trigger is:
trigger SDRDemoUpdate_test on Event (before update) {
Map<ID,Event> records = New Map<ID,Event>([SELECT CreatedBy.Name FROM Event WHERE ID IN: trigger.new]);
for (Event obj :Trigger.new){
obj.SDR_Original_Demo__c = records.get(obj.id).CreatedBy.Name;
}
}
Now I am trying to write code for its test class. It is giving error on line saying object can not be parsed to String.
Code For Test Class is:
#isTest
public class originalDemo {
static testMethod void test_original_demo() {
Event obj = new Event();
obj.CreatedBy = 'Tom';
obj.Owner = 'Jack';
obj.What = 'Opportunity';
insert.obj;
userInfo.getName();
}
}
Looking forward to find out the solution. Any help would be appreciated.
Thanks
Your issue in these lines
obj.CreatedBy = 'Tom';
obj.Owner = 'Jack';
obj.What = 'Opportunity';
You tried to pass String to fields which required Id.
User user = [SELECT Id FROM User LIMIT 1];
obj.CreatedById = UserInfo.getUserId();
obj.OwnerId = user.Id;
obj.WhatId = opportunity.Id;
I am struggling to get my head around this since too many hours and I need some help.:)
I have a website build on Kohana and want to dynamically change the content of some text when the user click one button or and another. Not sure if I am doing it the right way but this what I did so far (ho by the way I am new to this framework).
Controller:
class Controller_Homepage extends Controller_General {
public $template = "template/widepage";
public $textbuyer = array (
'text1' => "homepage.buyer.bigtext1", //transfering language variable.
'text2' => "homepage.buyer.bigtext2",
//with more ...
);
public $textseller = array (
'text1' => "homepage.seller.bigtext1",
'text2' => "homepage.seller.bigtext2",
'text3' => "homepage.seller.bigtext3",
//with more ...
);
public $thetext = array ("textbuyer"); //the defaul array is textbuyer
public function action_index() {
$this->content = View::factory("homepage")
->bind('pagetext', $thetext );
if ($this->request->method() === Request::POST) {
$post= $this->request->post();
if (isset($post['buyer'])){
$thetext = $textbuyer;//gives rrorException [ Notice ]: Undefined variable: textbuyer
// arr::overwrite($thetext, $textbuyer);
}else if(isset($post['seller'])){
$thetext = $textseller;
}
}
}
Section of my view to show how I use the variable in the view:
<div class="container_content">
<div>
<p id='sline'><?php echo $pagetext['text1']; ?></p>
</div>
<div>
Can't get the content of my array to the view and when I click on one of the two buttons this code gives me the following error: ErrorException [ Notice ]: Undefined variable: textbuyer. What I am doing wrong ? Why I get the error I mentionned ?
Thank you!
When you define the variables like this
public $textbuyer = ...
public $textseller = ...
public $thetext = ...
They are attributes of your class. And since they are, you need to call them via
$this->textbuyer
$this->textseller
$this->thetext
Just as you call methods inside the same class with $this->methodName() instead of methodName().
class Foo {
public $bar = "hello ";
public function foo() {
$bar = "world";
print $this->bar.$bar; // hello world
}
}
This would work just fine and you get the error because you never define $textbuyer (because you want to call $this->textbuyer).
I have three const in controller:
const TEST1 = 1;
const TEST2 = 2;
const TEST3 = 3;
How I can call these values in view as a dropDown?
If you will get messy with all constants you have in diferent models, you can use code snippet I wrote to manage them. Please see Managing constants easily (yii wiki article)
I will copy just function and one example, but for full wiki and details please go visit link above.
Put this method in parent class or your model class directly:
class ActiveRecord extends CActiveRecord {
const TEST_1 = 1;
const TEST_2 = 2;
const TEST_3 = 3;
/*
Get class constants by token.
If you set constants with same prefix, like:
TEST_1
TEST_2
TEST_3
, you can get it by calling
Class::getConstants('TEST_');
*/
public static function getConstants($token,$objectClass) {
$tokenLen = strlen($token);
$reflection = new ReflectionClass($objectClass); //php built-in
$allConstants = $reflection->getConstants(); //constants as array
$tokenConstants = array();
foreach($allConstants as $name => $val) {
if ( substr($name,0,$tokenLen) != $token ) continue;
$tokenConstants[ $val ] = $val;
}
return $tokenConstants;
}
}
And after that you can use this method to get specific constants (from one group) in array:
self::getConstants('TEST_',__CLASS__); //inside same class
ActiveRecord::getConstants('TEST_','ActiveRecord'); //outside, somewhere else in view or controller
For dropdown it would be looking as (if MyModel have parent ActiveRecord)
echo CHtml::dropDownList('name','selected',
MyModel::getConstants('TEST_','MyModel'),
array(// for htmlOptions
)
);
Now you can forget to edit all places in code if you adding new constant. It will automaticaly added to all your dropdowns or whatever.
Simple, just use:
$this::TEST1;
In dropdownList:
echo CHtml::dropDownList('name','selected',
array($this::TEST1=>'Test1',$this::TEST2=>'Test2',$this::TEST3=>'Test3'),
array(// for htmlOptions
)
);