将ng-model值指定为cakephp的默认值选择

时间:2015-08-12 06:55:15

标签: javascript angularjs cakephp

我正在使用一个函数来获取名字和姓氏的首字母,它工作正常。我现在面临的问题是我在ng-repeat中应用了这个功能。由于ng-repeat生成的列表中的选择没有默认值,因此我在空属性中获取值。现在我想将ng-model值指定为默认值。 JS功能获得缩写:

function getInitials(attrs,element)
{
   if(attrs.ulabel ){  
        var x = $(element).find(":selected").text();                
        console.log(x);
        var seperateWords = x.split(" ");
        var acronym = "";
        for (var i = 0; i < seperateWords.length; i++){
            acronym = (acronym + seperateWords[i].substr(0,1).toUpperCase());
        }

  if(element.parent().parent().find('label').text() ){
               element.parent().parent().find('label').text(acronym);
            } else 
      element.parent().parent().prepend('<label>'+acronym+'</label>');

            }

查看文件:

<ul ng-repeat=" opts in rootEntry['customer']  track by $index" class="sidebar_overview">
                <li class="inner-sidebar">   
                    <ul class ="inner_sidebar_check">
                        <li class="custov_chk">
                            <?php 
                            echo $this->Form->checkbox('cid', array('hiddenField' => false, 'value' => '{{opts.Customer.customerid}}', 'ng-model' => "opts.Selected")); 
                            ?>
                        </li>
                        <li class="co_cn" ng-click="gotoprofile(opts.Customer.customerid)">{{opts.CustomerProfile.firstname | limitTo: 8}} {{opts.CustomerProfile.lastname | limitTo: 8}}</li>
                        <li class="inner_cust_date">{{opts.Customer.addedon}}</li> 
                    </ul>
                </li> 
                <li ng-class-odd="'list1'" ng-class-even="'list2'">
                    <div ng-style="resizeWithOffset(300,220,150);" class="outer-sidebar label-outer-sidebar">
                        <ul>
                            <li class="col-lg-2 col-md-2 col-sm-6 col-xs-6"><?php
                                echo $this->Acs->userdropdown('allocatedtoprimaryid', array('label' => False, 'type' => 'select',
                                    'utype' => 'salesman',
                                    'anlabel' => true,
                                    'ng-model' => 'opts.AddedbyCustomer.allocatedtoprimaryid',
                                    'empty' => 'Salesman 1',
                                    'ng-hasfocus' => 'prime','ulabel' => 'true','class'=>'usr_drp_prime'
                                ));
                                ?>
                            </li>
                            <li class="col-lg-2 col-md-2 col-sm-0 col-xs-0"><?php
                                echo $this->Acs->userdropdown('allocatedtosecondaryid', array('label' => False, 'type' => 'select',
                                    'utype' => 'salesman',
                                    'anlabel' => true,
                                    'ng-model' => 'opts.AddedbyCustomer.allocatedtosecondaryid',
                                    'empty' => 'Salesman 2',
                                    'ng-hasfocus' => 'prime','ulabel' => 'true','class'=>'usr_drp_second'
                                ));
                                ?>
                            </li>
                            <li class="col-lg-2 col-md-2 col-sm-0 col-xs-0"><?php
                                echo $this->Form->input('action_seq_id', array('label' => False, 'type' => 'select',
                                    'options' => Configure::read('actionseq1'),
                                    'ng-model' => 'opts.AllocateActionSequenceFrontend.action_seq_id',
                                    'empty' => 'Select Action Sequence',
                                ));
                                ?>
                            </li>
                            <li class="col-lg-2 col-md-2 col-sm-0 col-xs-0"><?php
                                echo $this->Form->input('interestedinid', array('label' => False, 'type' => 'select',
                                    'options' => Configure::read('iaminterstedin'),
                                    'ng-model' => 'opts.CustomerDisposition.interestedinid',
                                    'empty' => 'Select Interested In',
                                ));
                                ?>
                            </li>
                            <li class="col-lg-3 col-md-2 col-sm-0 col-xs-0 src_tag">
                                <span>{{opts.SourceBackend.sourcename}}</span>
                                <span ng-bind="getButtonLabel(opts.CustomerDisposition.tagid)"></span>
                            </li>
                            <li class="col-lg-1 col-md-2 col-sm-6 col-xs-6 pull-right">
                                <div class="custov_action pull-right">
                                    <?php echo $this->Html->link('',array('controller' => 'Customers', 'action' => 'edit/{{opts.Customer.customerid}}/frommini','full_base' => true,), array('id' => 'custov_edit'));
                                          echo $this->Html->link('',array('controller' => 'Lead', 'action' => 'sethotleads/{{opts.Customer.customerid}}hotlead={{opts.CustomerProfile.hot_leads}}','full_base' => true,),array('id'=>'custov_lead'));
                                          echo $this->Html->link('',array('controller' => 'Customers', 'action' => 'custdelete_popup/{{opts.Customer.customerid}}/' . $_SESSION['user_id']), array('id'=>'custov_delete'));
                                    ?>
                                </div>

                            </li>
                        </ul>
                    </div>    
                </li>
            </ul>

0 个答案:

没有答案
相关问题