小编Kei*_*wer的帖子

javascript格式价格

我希望将变量格式化为价格格式,如果它是例如$ 90,则忽略它已经做过的小数.但如果价值是44.5美元,那么我想将其格式化为44.50美元.我可以在php而不是javascript中做到这一点.

PHP示例:

number_format($price, !($price == (int)$price) * 2);
Run Code Online (Sandbox Code Playgroud)

我要格式化的代码:

$(showdiv+' .calc_price span').html(sum_price);
Run Code Online (Sandbox Code Playgroud)

javascript format

4
推荐指数
1
解决办法
8170
查看次数

谷歌地图api错误:属性<waypoints>出错:

我试图在谷歌地图api上设置一些路标,但得到以下错误.我知道它与设置一个对象有关,但我似乎无法正确对待它.我也找不到任何确切的文章.

Error: Error in property <waypoints>: (Invalid value: Ballybricken, Waterford, Ireland,The Glen, Waterford (Error in element at position 0: (Unknown property <0>)))
Run Code Online (Sandbox Code Playgroud)

我的代码

var waypts = ["Ballybricken, Waterford, Ireland", "The Glen, Waterford"];
drawPolyline('Waterford Regional Hospital', 'Hillview, Waterford, Ireland', waypts);


function drawPolyline(source,destination,waypoints){
        // show route between the points
        directionsService = new google.maps.DirectionsService();
        directionsDisplay = new google.maps.DirectionsRenderer(
        {
            suppressMarkers: true,
            suppressInfoWindows: true,
            polylineOptions: { strokeColor: '#000000', strokeOpacity: 0.5 } 
        });
        directionsDisplay.setMap(map);
        var request = {
            origin:source, 
            destination:destination,
            waypoints:waypoints,
            travelMode: google.maps.DirectionsTravelMode.DRIVING
        };
        directionsService.route(request, …
Run Code Online (Sandbox Code Playgroud)

javascript google-maps-api-3

4
推荐指数
1
解决办法
2011
查看次数

cakephp 3多级相关保存

我有一个Users模型,它与Employees模型有一个hasOne关系.当我保存用户时,我还使用user_id在Employees表中添加记录.这很好用.

Employee可以通过CoursesEmployees表与belongsToMany课程相关联.当我只保存员工时,这可以保存.

我的问题是我要保存全部3个,但课程没有得到保存.

保存用户 - >使用新的user_id保存员工 - >在courses_employees中使用employee_id保存为新员工选择的课程

EmployeesTable.php

public function initialize(array $config)
{
    $this->table('employees');
    $this->displayField('name');
    $this->primaryKey('id');
    $this->addBehavior('Timestamp');
    $this->belongsTo('Users', [
        'foreignKey' => 'user_id',

    ]);
    $this->belongsTo('Hotels', [
        'foreignKey' => 'hotel_id',
        'joinType' => 'INNER'
    ]);
    $this->belongsToMany('Courses', [
        'foreignKey' => 'employee_id',
        'targetForeignKey' => 'course_id',
        'joinTable' => 'courses_employees'
    ]);
}
Run Code Online (Sandbox Code Playgroud)

用户add.ctp:

<?= $this->Form->create($user) ?>
<fieldset>
    <legend><?= __('Add User') ?></legend>
    <?php
        echo $this->Form->input('role_id', ['options' => $roles, 'empty' => true]);
        echo $this->Form->input('email');
        echo $this->Form->input('active');
        echo $this->Form->input('activation_key');
        echo $this->Form->input('password');
        echo $this->Form->input('employee.name');
        echo $this->Form->input('employee.email');
        echo $this->Form->input('employee.surname');
        echo $this->Form->input('employee.employee_num'); …
Run Code Online (Sandbox Code Playgroud)

cakephp cakephp-3.0

4
推荐指数
1
解决办法
1490
查看次数

Cakephp更新或添加新记录

我有一个图片上传,将文件名添加到名为附件的表中。如果该ID已经存在,那么我希望它进行更新,如果不存在,则创建一个新记录。目前它创建了一条新记录,因此我有一个ID的多个记录。ID来自称为Addon的表。

我不确定如何在cakephp中执行此操作。

    if (!empty($this->data)) {
        $this->layout = null;
        //if(empty($this->data['AddOn']['id'])){unset($this->data['AddOn']);}

        // restructure data for uploader plugin // NEED TO GET RID OF THIS ? MOVE IT
        $tmp_file = $this->data['Attachment'][0]['file'];
        $tmp_file['extension'] =  array_reverse(explode('.', $tmp_file['name']));
        $tmp_file['extension'] = $tmp_file['extension'][0];
        $tmp_file['title'] = strtolower(substr($tmp_file['name'],0,(0-strlen('.'.$tmp_file['extension']))));
        $this->data['Attachment'][0]['alternative'] = ucwords(str_replace('_',' ', $tmp_file['title']));

        $previous = $this->AddOn->Attachment->find('first', array('conditions'=> array('model'=>'AddOn', 'foreign_key'=>$id)));
        if( !empty( $previous ) ) {
            $this->AddOn->Attachment->id = $previous[ 'Attachment' ][ 'id' ];
        }

        if ($this->AddOn->save($this->data, array('validate' => 'first'))) {    

            $id = $this->AddOn->Attachment->getLastInsertID();

            $att = $this->AddOn->Attachment->query("SELECT * from attachments WHERE id …
Run Code Online (Sandbox Code Playgroud)

php cakephp

3
推荐指数
1
解决办法
5570
查看次数

jquery在循环中添加到变量

我试图添加到一个变量并在循环结束时获取总价,并将其添加到 span 标签中的值并更新它。我不确定如何使用 jquery,我通常使用 php 来做。这是我尝试过的,但我什么也没得到。

$.each(data, function(key, obj) {
    items.push('<li id="' + obj.id + '">' + obj.title + '€' + obj.price + '</li>');
    totalprice += obj.price
});

$("#addonPrice").html($("#addonPrice").text() + totalprice);
Run Code Online (Sandbox Code Playgroud)

variables jquery

3
推荐指数
1
解决办法
8895
查看次数

与cakephp简单的json响应

我试图将一些json传递给cakePHP 2.5中的控制器并再次返回它,以确保它完全正常.

但是我没有回复内容.只有200个成功.从阅读文档我的印象是,如果我传递一些json,那么responseHandler将返回json作为响应.

不确定我错过了什么.

数据被传递

var neworderSer = $(this).sortable("serialize");
Run Code Online (Sandbox Code Playgroud)

这使

item[]=4&item[]=3&item[]=6&item[]=5&item[]=7 
Run Code Online (Sandbox Code Playgroud)

appController.php

public $components = array(
    'DebugKit.Toolbar', 
    'Search.Prg', 
    'Session', 
    'Auth',
    'Session',
    'RequestHandler'
);
Run Code Online (Sandbox Code Playgroud)

index.ctp

    $.ajax({
        url: "/btstadmin/pages/reorder",
        type: "post",
        dataType:"json",
        data: neworderSer,
        success: function(feedback) {
            notify('Reordered pages');
        },
        error: function(e) {
            notify('Reordered pages failed', {
                status: 'error'
            });
        }
    });
Run Code Online (Sandbox Code Playgroud)

PagesController.php

public function reorder() {

    $this->request->onlyAllow('ajax');
    $data = $this->request->data;
    $this->autoRender = false;
    $this->set('_serialize', 'data');

}
Run Code Online (Sandbox Code Playgroud)

更新:我现在已将以下内容添加到routes.php中

    Router::parseExtensions('json', 'xml');
Run Code Online (Sandbox Code Playgroud)

我已将控制器更新为

    $data = $this->request->data;

    $this->set("status", "OK");
    $this->set("message", "You are good");
    $this->set("content", $data); …
Run Code Online (Sandbox Code Playgroud)

ajax json cakephp

3
推荐指数
1
解决办法
1万
查看次数

Cakephp中是否有邻居的替代品

我将我的应用程序覆盖到cakephp 3.0,并且在查找方法中找不到使用邻居的替代方法时遇到了麻烦。

我需要在关联的表中找到下一条记录,而邻居是完成记录的好方法。

//Open courses
$options = [
    'conditions' => ['Employees.user_id' => 1, 'CoursesEmployees.completed' => false],
    'limit' => 3,
    'contain' => 'Employees'
];
$recentOpen = $this->CoursesEmployees->find('all', $options)->toArray();

// get next module for each open course
foreach ($recentOpen as $key => &$value) {
    $currentModule = $value['CourseModule']['id'];
    $neighbors = $this->CoursesEmployees->CourseModules->find(
        'neighbors',
        ['field' => 'id', 'value' => $currentModule]
    );
    $value['CourseModule']['next_module'] = $neighbors['next']['CourseModule']['name'];
};
Run Code Online (Sandbox Code Playgroud)

我发现的代码的另一个问题是,$this->CoursesEmployees->find('all', $options)->toArray();似乎返回了一个复杂数组,其中cakephp用于查询表的所有内容,而不是像cakephp 2那样的实际结果。我在->toArray()3.0中推荐添加

cakephp cakephp-3.0

3
推荐指数
1
解决办法
904
查看次数

:第一个孩子没有选择第一段

我有两个包裹在div中的段落.我想让第一段文本稍大一些,但使用:first-child不能像我调用它一样工作.不知道出了什么问题.

        <div id="main-content">
            <h2 class="title">
                About Us
            </h2>
            <p>Formerly Days Hotel Waterford, Treacys Hotel Spa & Leisure Centre is situated in the heart of Waterford City in Ireland's Sunny South-East, and is proud to be one of the finest hotels in Waterford.  The hotel is the perfect choice for your business, leisure and family breaks.  Guests can dine in Croker's Restaurant, enjoy a drink with friends in Timbertoes bar, relax in the swimming pool or Jacuzzi at Spirit Leisure Centre …
Run Code Online (Sandbox Code Playgroud)

css css-selectors

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

cakephp sum()在单场上

我已经搜索了如何获得一个名为积分的字段的高低.我只需要一个总数,但我能得到的最好的是Points表中的记录列表以及来自成员的相关记录.

    $totalPoints = $this->Member->Point->find('all', array(
               array('fields' => array('sum(Point.points)   AS Point.ctotal'))));
Run Code Online (Sandbox Code Playgroud)

cakephp

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

使用变量作为对象键

我希望将变量插入对象键结构中,但我只获取变量名称而不是变量值。

var winnerId = 10;
var loserId = 11;        

newMessage.setMessageData({
  winnerId : {
    "status" : "win",
    "choice" : playerData[winnerId]["currentChoice"],
    "newScore" : playerData[winnerId]["score"]
  },
  loserId : {
    "status" : "lost",
    "choice" : playerData[loserId]["currentChoice"],
    "newScore" : playerData[loserId]["score"]
  }           
});
Run Code Online (Sandbox Code Playgroud)

javascript

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