小编vrt*_*515的帖子

更改DetailView小部件中属性的值

我有一个名为Play的表,我在Yii2详细视图小部件中显示每条记录的详细信息.我在该表中有一个属性recurring为tinyint 的属性,它可以是0或1.但我不想将其视为数字,而是我想显示yesno基于值(0或1).

我正在尝试使用detailview小部件中的函数更改它,但我收到一个错误: Object of class Closure could not be converted to string

我的详细视图代码:

 <?= DetailView::widget([
    'model' => $model,
    'attributes' => [
        'name',
        'max_people_count',
        'type',
        [
             'attribute' => 'recurring',
             'format'=>'raw',
             'value'=> function ($model) {
                        if($model->recurring == 1)
                        {

                            return 'yes';

                        } 
                        else {
                        return 'no';
                        }
                      },
        ],
        'day',
        'time',
        ...
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激 !

detailview yii2

8
推荐指数
2
解决办法
2万
查看次数

多个API调用,并在chain和Promise.all中进行提取

我正在函数中进行API调用以获取一些数据。然后,我需要根据第一个调用中的特定值,对返回的每个数据项进行多个API调用。我在渲染状态时遇到问题,在渲染期间不存在从多个promise添加的值。

到目前为止,我有这样的事情:

fetch(url)
.then(resp => resp.json())
.then(data => {
  //do some calculations and populate new array and return it
})
.then(data => {
   const newData = [...data];
   Promise.all(functionWhichReturnsArrayOfPromises).then(el => {
      // more calculation
      newData.push(el.someValue);
   })
   return newData;
})
.then(data => this.setState({data: data}))
Run Code Online (Sandbox Code Playgroud)

返回promise数组的函数如下所示:

fetchMoreData(arr) {
   const promises = arr.map(el => {
      return fetch(someUrl)
      .then(data => data.json())
      .then(data => data)
   })
   return promises;
}
Run Code Online (Sandbox Code Playgroud)

我认为将Promise.all链接到另一个Promise不好,是否有推荐且更优雅的方式来实现此目的?

javascript fetch reactjs es6-promise

2
推荐指数
1
解决办法
132
查看次数

标签 统计

detailview ×1

es6-promise ×1

fetch ×1

javascript ×1

reactjs ×1

yii2 ×1