我需要一些帮助来理解如何从继承的小部件获取数据。
我通常使用直接从构建方法从我的小部件获取参数
@override
Widget build(BuildContext context) {
//THIS METHOD
var data = StateContainer.of(context).data;
return Container(child:Text("${data.parameter}"));
}
Run Code Online (Sandbox Code Playgroud)
但是这个方法不能从 initState 调用,因为还没有 buildContext 。
我需要在 initState 方法中使用该参数(我在其中调用了从服务器获取的数据,并且需要将该数据传递给我的函数),那么,我该怎么做呢?
@override
void initState() {
otherData = fetchData(data);
super.initState();
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用 didChangeDipendencies() 但每次重建视图时都会调用它(从屏幕弹出等),所以它不是我想要使用的,也不是 FutureBuilder 小部件。
有什么建议吗?
我有ajax和bootstrap表的问题.我有一个用这个方法调用的ajax JSON:
$(document).ready(function(){
$.ajax({
url: 'php/process.php?method=fetchdata',
dataType: 'json',
success: function(data) {
$('#clienti').bootstrapTable({
data: data
});
},
error: function(e) {
console.log(e.responseText);
}
});
});
Run Code Online (Sandbox Code Playgroud)
我的JSON似乎正确,但表格没有显示任何记录.我究竟做错了什么?
这也是表定义
<table data-toggle="table" class="display table table-bordered" id="clienti">
<thead>
<tr>
<th>Nome</th>
<th>Cognome</th>
<th>Data Nascita</th>
<th>Provincia</th>
<th>Comune</th>
<th>CAP</th>
<th>Indirizzo</th>
<th>Fisso</th>
<th>Cellulare</th>
<th>Note</th>
</tr>
</thead>
</table>
Run Code Online (Sandbox Code Playgroud)
这也是返回的json的一部分
[{"Nome":"","Cognome":"","DataN":"0000-00-00","Provincia":"","Comune":"","CAP":"","Indirizzo":"","Fisso":"","Mobile":"","Note":""},{"Nome":"Federico","Cognome":"Lupieri","DataN":"2015-09-16","Provincia":"","Comune":"","CAP":"34170","Indirizzo":"Via Ascoli 1","Fisso":"00112233445566","Mobile":"00112233445566","Note":"Vediamo se funziona questo"},
Run Code Online (Sandbox Code Playgroud)