Corona SDK: TableView index not updating - indexing

I've got a problem with Corona SDK and the tableview, but allow me to show the code first:
function functions.onRowTouch( event )
print("ONROWTOUCH EXECUTING")
if event.phase == "tap" or event.phase == "press" then
print("EVENT.TARGET.INDEX: " .. event.target.index)
editItemNum = event.target.index
print("editnum: " .. editItemNum)
print("ITEM tapped")
if saveData.names[event.target.index] ~= nil then
function functions.pressRow(event)
print("ROW NUM: " .. event.target.index)
print("EDITNUM = " .. editItemNum)
functions.pressItem()
return true
end
event.target:addEventListener("tap", functions.pressRow)
end
elseif event.phase == "swipeLeft" then
print("SWIPING LEFT")
tableView:deleteRows({event.target.index}, {slideLeftTransitionTime=450})
table.remove(saveData.names, editItemNum)
table.remove(saveData.dates, editItemNum)
table.remove(saveData.amounts, editItemNum)
loadsave.saveTable(saveData, "payMeBackTable.json")
print("ROW DELETED")
end
end
I'm sorry for the indentation, stackoverflow just kept changing it...
But here is my question:
in the event.phase == "tap", I'm assigning editItemNum to event.target.index. After that I delete a row that is tapped. This works great for the first time. I'm using this line of code to achieve that btw:
tableView:deleteRows({editItemNum}, {slideLeftTransitionTime=400} )
So the delete function knows what to delete because "editItemNum" gets the value of the row index.
But once I deleted the row, the index numbers of the rows are not adapting. So for example I've got 3 objects in my table: 1,2,3. Now I delete the middle one, so I should get: 1,2. But instead when I touch the second row, the index is still 3. So visually that'd look like: 1,3.
It just makes no sense in my eyes and I really don't see anything wrong with my code. I did find a post on the Corona SDK forums with a bug report for this issue, but that was 2 years ago and was resolved...
Any help? :)
Kind regards,
Bram

Related

Why does pinescript place orders two candles after a trigger condition

I'm having some issues where my pinescript algo is placing orders two candles after my trigger conditions. My friends are also having the same issue. Does anyone know why this is the case and what I can do to solve it?
My code (I'm using HullMA as the trigger)
/////////////////Trend Indicator/////////////////
malength = input(defval=26, title="Moving Average Length", minval=1)
tsrc = security(heikinashi(syminfo.tickerid),"15", close)
hullma(tsrc, len) =>
hma = wma(2 * wma(tsrc, len / 2) - wma(tsrc, len), round(sqrt(len)))
zlema =hullma(tsrc, malength)
col = zlema > zlema[1] ? color.green : color.red
plot(zlema,color=col, linewidth=4)
/////////////////Buy and Sell Orders/////////////////
//Order conditions
if col == color.green
strategy.entry(id="long", long=true)
if col == color.red
strategy.entry(id="short", long=false)
Problem:
Found the solution, pinescript waits for candle closes and doesn't immediately initialise solutions, hence it takes two candles after the initial trigger before there is a signal

Trying to setState using eval() function (React Native)

I'm trying to set multiple states in a for loop to be false or true depending on whether they meet the (if statement) requirement. The for loop will loop through an array of strings, each string represents a state. But I can't seem to use eval within this.setState function...
I have tried researching online but none of the solutions match my problem or what I'm trying to solve. I even tried eval(this.state.anything) = false but it still doesn't work and shows a left hand assign invalid error.
let businessState = [
"this.state.groupName",
"this.state.groupOwnerName",
"this.state.groupDesc",
"this.props.profile._id",
"this.state.businessName",
"this.state.businessDesc",
"this.state.businessRegNo",
"this.state.businessType",
"this.state.businessEmail",
"this.state.businessTel",
"this.state.businessWeChat",
"this.state.businessRegPhotoUri",
"this.state.businessSignPhotoUri"
];
var temp = ""
for (i = 0; i < businessState.length; i++) {
if (eval(businessState[i]) == ""){
temp = businessState[i]+ "Error"
this.setState({
eval(temp): true
})
}
}
As you can see from the code above, I want to evaluate the state, and if the value that this particular state holds is an empty string "", I want to set this state name + "Error" (For example, if this.state.email is empty string "" I want to set this.state.emailError to true.
Instead of this.setState({eval(temp): true}) try this.setState({[temp]: true}). The brackets will output the string value stored in temp as a variable name in setState.
This article gives a good explanation
This Stack Overflow question and the accepted answer also should help

Checking if GroovyRowResult field is empty string

I am using sql.firstRow to check if a row exists in the postgres database based on some criteria.
def cur = sql.firstRow(r, '''
SELECT "some_thing"
FROM "my_table"
WHERE "customer_name" = :customer_name
AND "sad_date" = :sad_date
AND "forgiver" = :forgiver
''')
I find that this works:
if (cur){
log.debug("Found Some thing " + cur["some_thing"])
log.debug("Cur: " + cur.keySet())
}
however this lets in any rows that don't have some_field inside it.
ISSUE
To avoid this, when we try and check for the existance of a non empty value for some_field on the result row like this:
if (cur && "${cur.some_thing}" ){
log.debug("Found Some thing " + cur["some_thing"])
}
ERROR
I get an error suggesting that:
No signature of `String.positive` for argument types for the given type.
I have read this question and changed from cur.some_thing and cur['some_thing'] to "${cur.some_thing}" but the error does not go away
I have also tried this post and tried to use cur.getProperty("some_thing") and it still throws the same error.

Use Jade to dynamically fill a bootstrap caraousel. Some issues on iteration

I am trying to create a boostrap carousel using jade to dynamically iterate through a list of objects and display them in the carousel.
My first question is obviously is this possible.
Secondly how might I go about accomplishing it.
Here is a snippet of my code where I am trying to generate the list containing the data-slide-to to element of my carousel :
10 - var n = 0
11 while n < newsarticles.length
12 if n == 0
13 li.active(data-target="#header-carousel",data-slide-to="n++")
14 else
15 li(data-target="#header-carousel",data-slide-to="n++")
I know this is bad code but I am failing and finding a reference on how to accomplish this if it is possible.
The error it is throwing is
"unexpected text " pointing to line 13
Any advice would be greatly appreciate. Thank you for you time in advance and if there is any more information I can provide that would be helpful please let me know.
Here is a full working example of my dynamic carousel code:
extends layout
block content
div.container
#header-carousel.carousel.slide(data-ride="carousel",data-interval="4000")
ol.carousel-indicators
-var n = 0
while n < newsarticles.length
if n == 0
li.active(data-target="#header-carousel",data-slide-to=n)
- n++
else
li(data-target="#header-carousel",data-slide-to=n)
- n++
.carousel-inner
-var i = 0
- for newsarticle in newsarticles
if i == 0
.item.active
img(src='#{newsarticle.imgurl}')
.carousel-caption #{newsarticle.articletitle}
-i++
else
.item
img(src='#{newsarticle.imgurl}')
.carousel-caption #{newsarticle.articletitle}
-i++
a.left.carousel-control(href="#header-carousel", data-slide="prev")
span.icon-prev
a.right.carousel-control(href="#header-carousel", data-slide="next")
span.icon-next
the data associated with this code is as follows:
newsarticle =
{
articletitle: String,
bodytext: String,
editedon: { type: Date, default: Date.now },
imgurl: String
});
i guess issue would be the string you have n++ increment value in quotes.
i guess you can use a variable for it and then assign it to the data attribute.
Hey I have arrived at a working solution. Thank you everyone for taking a look. The way I achieved what I was attempting to do was by using #Jai's advice along with a little external thinking on my own. The issue was definanly the "" around the n++ but it was also trying to increment the variable n inside of the data-slide-to element. If you remove the quotations around it and then increment the variable n separately it works properly. Here is the working version of the code. Also if this is not the best industry practice and there is a better method of accomplishing this I am open to more solutions.
-var n = 0
while n < newsarticles.length
if n == 0
li.active(data-target="#header-carousel",data-slide-to=n)
- n++
else
li(data-target="#header-carousel",data-slide-to=n)
- n++

Output alternate field in case bound field is null on a Kendo MVC Grid ClientTemplate

I have a cell in a kendo MVC grid that I'd like to take one of two data fields depending on the value of one:
#(Html.Kendo().Grid(Of RTFVM)().Name("RealTimeFinancials") _
.Columns(Sub(c)
c.Bound(Function(x) x.Line.LineItem).HtmlAttributes(New With {.style = "text-align:left"})
c.Bound(Function(x) x.Line.Months(0).Total).Format("0:#,##0}").ClientTemplate("#if(data.Line.Months[0].Message == null) {data.Line.Months[0].Total} else {data.Line.Months[0].Message} #")
End Sub) _
etc
The cell is rendering as blank every time regardless of the result of the null comparison. I must be missing something obvious!
The #...# template markup just executes JS but does not output anything.
Instead, try #:...# or #=...# which both output a value back to the HTML, or this template:
#if(data.Line.Months[0].Message == null) {##:data.Line.Months[0].Total##} else {##:data.Line.Months[0].Message##}#
(it looks weird on 1 line, but if you were to insert line breaks it would make more sense:)
#if(data.Line.Months[0].Message == null) {#
#:data.Line.Months[0].Total#
#} else {#
#:data.Line.Months[0].Message#
#}#
I think this template might also work:
#: data.Line.Months[0].Message ?? data.Line.Months[0].Total #
Which would use the null-coalescing operator to use Total in the case where Message is falsey.