小编Oze*_*ich的帖子

Knockout:在一个元素中单击并检查绑定

我有一系列限制,以及启用/禁用限制的复选框.但是复选框不起作用

的jsfiddle

function Limit(start, end)
{
    var that = this;

    this.start = start;
    this.end = end;

    this.label = ko.computed(function(){
        return that.start + ' - ' + that.end;            
    });
}

function ViewModel()
{
    var that = this;

    this.limits = [new Limit(1,2), new Limit(3,4), new Limit(4,5)];

    this.activeLimit = ko.observable(that.limits[0]);

    this.changeActiveLimit = function(limit)
    {
            that.activeLimit(limit);
    }
}

ko.applyBindings(new ViewModel());?
Run Code Online (Sandbox Code Playgroud)

我的HTML

<div data-bind="foreach: {data: limits, as: 'limit'}">
 <input type="checkbox" data-bind="click: $root.changeActiveLimit, checked: limit.label == $root.activeLimit().label"/>
    <span data-bind="text: limit.label"/> 

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

javascript knockout-2.0 knockout.js

14
推荐指数
2
解决办法
4480
查看次数

vertical-align:按钮中文本的中间位置

我有这个布局:

布局

我的CSS:

body {
     background: #e2eaed;
}
a {
     text-decoration: none;
     color: #fff;
     font-size: 30px;
     height: 62px;
     line-height: 62px;
     /* vertical-align: middle is not works  */
     background: #8dc73f;
     width: 132px;
     padding: 0 25px;
     font-size: 16px;
     text-align: center;
     font-weight: bold;
     margin-left: 4px;
     display: block;
     float: left;
}
Run Code Online (Sandbox Code Playgroud)

当按钮有1行文本时,我的代码运行良好.但是当按钮有2行文本时,如上图所示.代码文本有很高的高度,因为我使用了line-height属性.我试过了vertical-align但是没有用.

请看jsfiddle.

css button vertical-alignment

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

如何为模型的所有搜索操作设置默认条件?

我有一个模特:

class Service extends CActiveRecord
{
    public static function model($className = __CLASS__)
    {
        return parent::model($className);
    }

    public static function getMainPageItems()
    {
        return self::model()->findAll(array(
            'condition' => 'on_main = 1',
            'order' => 'pos ASC'
    ));

    public static function getNonMainPageItems()
    {
        return self::model()->findAll(array(
            'condition' => 'on_main = 0',
            'order' => 'pos ASC'
    ));
}
Run Code Online (Sandbox Code Playgroud)

我想将模型的默认顺序设置为pos ASC.

如何设置模型的默认顺序?

php activerecord criteria yii

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