有没有办法以浓缩形式这样做?
GLfloat coordinates[8];
...
coordinates[0] = 1.0f;
coordinates[1] = 0.0f;
coordinates[2] = 1.0f;
coordinates[3] = 1.0f;
coordinates[4] = 0.0f;
coordinates[5] = 1.0f;
coordinates[6] = 0.0f;
coordinates[7] = 0.0f;
return coordinates;
Run Code Online (Sandbox Code Playgroud)
有点像coordinates = {1.0f, ...};?
我有一个ActiveRecord BaseModel类和许多继承它的类模型.而且我有一个类Bookmark,也是继承的BaseModel.此外,我有Decorator-inherited类,他们实现了特殊的接口来表示单个模型(getModelView(model)方法).这是一些伪代码:
TestModel inherits BaseModel
getName:
return this.name
BookmarkModel inherits BaseModel
BaseModel model
getBookmark:
return this.model
TestDecorator inherits BaseDecorator implements SingleModelViewInterface:
getView(model):
return 'view' //html-view of model
BookmarkDecorator inherits BaseDecorator
getBookmarksView(BookmarkModel[] bookmarks):
foreach(bookmarks > bookmark):
decorator = Relation::getDecoratorByModel(bookmark->getEntityType())
decorator->getView(bookmark->getBookmark())
Run Code Online (Sandbox Code Playgroud)
所以,一切看起来都不错,直到我想稍微更改该书签模型的View.我想要为该视图添加自定义标题.而且我无法在装饰器内部制作它,因为它不仅仅是用于书签.
编辑:所以,问题是 - 似乎我需要一个装饰模式,但我没有任何东西可以继承,因为具体的TestDecorator使用TestModel的特殊方法.所以现在我使用魔术方法(PHP)完成了一些非常糟糕的实现:
class BookmarkedModel {
/** @var BaseEntityModel*/
private $model;
public function __construct(BaseEntityModel $model) {
$this->model = $model;
}
public function getName() {
return 'Bookmark '.$this->model->getName();
}
public function __call($name, …Run Code Online (Sandbox Code Playgroud) 问题是我无法将文件保存到blob.它没有任何错误,临时文件创建,我可以从中读取.我检查了它是否会绑定 - 是的,它与正确的资源值和\PDO::PARAM_LOB数据类型一致.
我有一个ActiveRecord类:
class News extends ActiveRecord
{
public function rules()
{
return [
[
['image'],
'image',
'extensions' => 'png jpg',
'maxSize' => 1024 * 300,
]
];
}
public function beforeSave($insert)
{
$fileInfo = UploadedFile::getInstance($this, 'image');
$this->image = fopen($fileInfo->tempName, 'r+');
return parent::beforeSave($insert);
}
}
Run Code Online (Sandbox Code Playgroud)
表:
CREATE TABLE NEWS
(
RN NUMBER(17,0) PRIMARY KEY NOT NULL,
IMAGE BLOB
);
Run Code Online (Sandbox Code Playgroud)
显示此查询的日志:
INSERT INTO "NEWS" ("IMAGE") VALUES (:qp4) RETURNING "RN" INTO :qp8
Run Code Online (Sandbox Code Playgroud)
所以它实际上并没有绑定它或什么?
我是通过信号和插槽获取服务器数据的.这是插槽部分:
QString text(this->reply->readAll());Run Code Online (Sandbox Code Playgroud)
Problem is, that in text variable will be unicode escape, for example:
\u043d\u0435 \u043f\u0430\u0440\u044c\u0441\u044f ;-)Run Code Online (Sandbox Code Playgroud)
Is there any way to convert this?
有没有办法让这段代码更漂亮?
strong = li.find_all("strong")
if strong:
yield li.find_all("strong")
我的意思是这样的:
strong = li.find_all("strong")
yield li.find_all("strong") if strong
我正在尝试检查输入是否已更改.问题是 - 如果我将使用此代码:
trigger.keyup(function() {
current_input = getSearchString();
is_changed = (current_input != previous_input);
previous_input = current_input;
});
Run Code Online (Sandbox Code Playgroud)
当用户在短暂延迟"E"(输入值将为"QE")之后按下(例如"Q")并首先释放"Q"键时,该逻辑将中断.previous_input将被设置为"QE".用户发布"E"键和脚本比较相等的字符串.所以,当输入实际上发生了变化时,对于我的脚本则不然.知道如何解决这个问题或有没有不同的方法来做到这一点(不是用html5事件'输入')?
对不起这个令人困惑的标题.我想要做的是一个函数(或者只是一个简单的方法),它将执行简单的.next(),但如果没有下一个元素,则先匹配.对于.prev()也一样 - 如果没有前一个元素,则匹配最后一个.所以我这样做了:
var current_selected = getSelected();
if(current_selected.length) {
var prev = current_selected.prev();
if(prev.length) {
setSelected(prev);
return;
}
}
setSelected(getLast());
Run Code Online (Sandbox Code Playgroud)
但我真的不喜欢它,我认为有一些漂亮的方式做到这一点.有什么想法吗?(getSelected和getLast返回jQuery对象.
javascript ×2
jquery ×2
php ×2
activerecord ×1
arrays ×1
blob ×1
c ×1
declaration ×1
escaping ×1
generator ×1
oop ×1
oracle ×1
python ×1
python-3.x ×1
qt ×1
unicode ×1
utf-8 ×1
yield ×1
yii2 ×1