Reputation: 2433
The following js returns an error as below when trying to complete a conditional statement if( asset_type.indexOf("true,false") >= 0 )
I have tried to convert asset_type to string... and all fail
Error:
asset_type.get is not a function
the folowing code does return
console.log("Asset Type (row " + i + "): " + asset_type );
Asset Type (row 12): true,false
Code:
$("#myTable_asset").children("tbody").children("tr").each(function (i) {
var $this = $(this);
var my_td = $this.children("td");
var second_col = my_td.eq(1);
var third_col = my_td.eq(2);
second_col.find("input[type=text]").val(function(i, val) {
return val.replace(/\$|,/g, '');
});
var asset_value = second_col.find("input[type=text]").val();
var asset_type = third_col.find(":checkbox").map(function(_, el) { return el.checked }).get()
console.log("Asset Type (row " + i + "): " + asset_type );
try {
if ( '' != asset_type)
{
console.log("Asset Cost (row " + i + "): " + parseFloat(asset_value));
console.log("Asset Type (row " + i + "): " + asset_type );
if( asset_type.indexOf("true,false") >= 0 )
{
capex_value += parseFloat(asset_value);
}
if(asset_type.get().indexOf("false,true") >= 0 )
{
opex_value += parseFloat(asset_value);
}
}
}
catch(err) {
console.log(err.message);
}
});
a print out of third_col.html() gives the following:
<fieldset data-role="controlgroup" data-type="horizontal" class="ui-controlgroup ui-controlgroup-horizontal ui-corner-all">
<div class="ui-controlgroup-controls ">
<div class="ui-checkbox ui-mini">
<label for="asset_allocation_capex_19" class="ui-btn ui-corner-all ui-btn-inherit ui-checkbox-off ui-first-child">
Capex
</label>
<input type="checkbox" name="asset_allocation_capex_19" id="asset_allocation_capex_19" data-mini="true">
</div>
<div class="ui-checkbox ui-mini">
<label for="asset_allocation_opex_19" class="ui-btn ui-corner-all ui-btn-inherit ui-checkbox-on ui-btn-active ui-last-child">
Opex
</label>
<input type="checkbox" name="asset_allocation_opex_19" id="asset_allocation_opex_19" data-mini="true" checked="">
</div>
</div>
</fieldset>
Upvotes: 0
Views: 46
Reputation: 3091
I think that you forgot that you already used get() on jquery elements here:
var asset_type = third_col.find(":checkbox").map(function(_, el) {
return el.checked }).get()
Just check your code.
Upvotes: 0
Reputation: 121
asset_type is an array of [true, false].
You cant do get()
or indexOf('true,false')
.
You can do:
var first = asset_type[0], scond = asset_type[1];
if(first=== true && second === false){...}
else if(first=== false && second === true){...}
Upvotes: 1