【发布时间】:2022-01-06 03:07:51
【问题描述】:
我正忙于尝试从后端字符串值在前端创建一个 if 语句
上图来自后端,我将 $blody1$ 替换为
所以最终它会是这样的 [Guest].length > 1
有没有办法将其转换为真或假,如果没有任何帮助的指针。我想将逻辑移到后端,但我相信我也会在那里遇到同样的问题。
旁注最终结果应该类似于 {"color" : "blue"} OR {"color" : "orange"}
我的代码
const start = "\$";
const end = "\$";
final startIndex = str.indexOf(start);
final endIndex = str.indexOf(end, startIndex + start.length);
String tValue =
str.substring(startIndex + start.length, endIndex);
String tcondition = str.substring(endIndex + 1);
print(getValue(tValue).toString() + tcondition);
谢谢
【问题讨论】:
-
无法将任意字符串评估为代码。这既不切实际,又是等待发生的任意代码执行漏洞。充其量您可以构建一个
Map<String, dynamic>将字符串"Guest"映射到Guest变量引用的对象,然后在解析传入的字符串时使用它。 -
明白,我需要再调查一下...谢谢
标签: flutter dart dynamic backend dynamic-programming