小编cno*_*ris的帖子

如何使用yii以持久方式显示基于下拉列表的动态代码?

当yii中的下拉列表更改时,我会渲染一些表单元素,如下所示:

$form->dropdownListRow($model, 'type', array('item1','item2','etc') ,
    array('ajax'=>array(
        'type'=>'POST',
        'url'=>CController::createUrl('ProfileFieldRule/showAttributes'),
        'update'=>'#showAttributes',                        
    ))
));
Run Code Online (Sandbox Code Playgroud)

ProfileFieldRule/showAttributes使用CHtml渲染表单元素,这导致了我的第一个问题 - 我必须使用opentag等,并重复在表单中完成的工作.

echo CHtml::openTag('div', array('class' => 'control-group '));
echo CHtml::activeLabel($attr, $name, array('class' => 'control-label'));
etc
Run Code Online (Sandbox Code Playgroud)

第二个问题是:如果没有更改事件(例如提交的表单有错误),则不会加载动态内容.

我正在传递模型并检查它是否为null,否则执行与ProfileFieldRule/showAttributes相同的渲染,例如:

   <div id="showAttributes">
    <?php if (isset($attr)) {
        //do the same rendering as in showAttributes
        $vars = get_class_vars(get_class($attr));
             foreach ($vars as $name => $value) {
                 //etc...
    ?>
    </div>
Run Code Online (Sandbox Code Playgroud)

如果我可以调用上面的代码onload,onchange,并且仍然可以访问$ form,那将是理想的选择.

我对任何事情持开放态度,那么如上所述,显示和保持动态内容的最佳(或好)解决方案是什么?

提前感谢任何建议.

编辑

这是一个正在发生的事情的图像http://imgur.com/cZjRZ 注意,渲染的元素没有显示ajax验证(以红色/绿色突出显示),因为我对ajax很不好并且还在计算

我应该注意,我考虑的另一个解决方案是摆脱showAttributes,继续将两个模型传递给表单,并在更改时再次调用create action.然而,当更改下拉列表时,这会删除之前的ajax验证,因为整个表单被重绘.

ajax jquery yii

9
推荐指数
1
解决办法
589
查看次数

如何使用React.js用类包围每个X元素

我只想做点如下的事情:

<div class="container">
  <div class="row">
    <div class="col-md-4">content</div>
    <div class="col-md-4">content</div>
    <div class="col-md-4">content</div>
  </div>
  <div class="row">
    <div class="col-md-4">content</div>
    <div class="col-md-4">content</div>
    <div class="col-md-4">content</div>
  </div>

   <!-- etc ... -->

</div>
Run Code Online (Sandbox Code Playgroud)

例如,每3个.col-md-4's被包裹在一个.row

我试过了:

rows.push(<div className="row">);

   for (var count = 0; count < 9; count++) { 

       rows.push( <!-- content --> );

       // Add closing and reopening divs every 3 elements
       if (count % 3 === 0) {
          rows.push(</div><div className="row">);
       }
   }

   rows.push(</div>);
}
Run Code Online (Sandbox Code Playgroud)

遗憾的是,这不起作用.

此外,3和9只是这里的例子,我想知道是否有通用的方法.

javascript reactjs react-dom

9
推荐指数
2
解决办法
2573
查看次数

如何从Ionic2中的离子输入中获取包裹的输入?

我想附加一个google.maps.places.Autocompleteion-input,但在Ionic2 ion-input包装的<input>元素,我无法弄清楚如何访问它.

我已经尝试创建一个指令并使用传入的 ElementRef

import {Directive, ElementRef, Input} from 'angular2/core';

@Directive({
    selector: '[location-picker]'
})

export class LocationPicker {
    constructor(el: ElementRef) {    
        console.log(el.nativeElement);    
    }
}
Run Code Online (Sandbox Code Playgroud)

nativeElement返回包装的输入.

<ion-input location-picker="">
    <input class="text-input ng-valid ng-dirty ng-touched" type="text" placeholder="" aria-labelledby="lbl-6" location-picker="" autocomplete="off" autocorrect="off">
    <!--template bindings={}-->
    <!--template bindings={}-->
    <!--template bindings={}-->
</ion-input>
Run Code Online (Sandbox Code Playgroud)

我还试图建立类似一个自定义组件和切换SearchbarTextInput,但TextInput doesn't have.inputElement`.

任何想法都会受到欢迎.

谢谢!

ionic-framework ionic2 angular

5
推荐指数
1
解决办法
1218
查看次数

标签 统计

ajax ×1

angular ×1

ionic-framework ×1

ionic2 ×1

javascript ×1

jquery ×1

react-dom ×1

reactjs ×1

yii ×1