我在离子v1中使用了这个插件,工作得很好.但我不知道如何将它添加到Ionic 2
无法建立项目,因为它无法找到cordova
import { Component } from '@angular/core';
import { Platform, NavController, NavParams } from 'ionic-angular';
@Component({
selector: 'page-scan-vehicle',
templateUrl: 'scan-vehicle.html'
})
export class ScanVehiclePage {
constructor(public platform: Platform, public navCtrl: NavController, public navParams: NavParams) {}
public scan () {
// open scanner
// save results
this.platform.ready().then(() => {
cordova.plugins.pdf417Scanner.scan()
});
}
}
Run Code Online (Sandbox Code Playgroud)
在这个例子中,他们也在做同样的事情.但如果它没有找到cordova,它将如何工作,我的意思是只有在建成后才添加cordova?
var http = require("http");
var sys = require('sys')
var filename = process.ARGV[2];
var exec = require('child_process').exec;
var com = exec('uptime');
http.createServer(function(req,res){
res.writeHead(200,{"Content-Type": "text/plain"});
com.on("output", function (data) {
res.write(data, encoding='utf8');
});
}).listen(8000);
sys.puts('Node server running')
Run Code Online (Sandbox Code Playgroud)
如何将数据流式传输到浏览器?
我发送一个创建新用户的POST,这是有效的.
我的问题是我如何回到例如创建用户的pk到ajax响应?
$.ajax({
url: 'http://localhost:8080/api/v1/create/user/',
type: 'POST',
contentType: 'application/json',
data: '{"uuid": "12345"}',
dataType: 'json',
processData: false,
success: function (r) {
console.log(r)
},
});
def obj_create(self, bundle, request=None, **kwargs):
try:
user = User.objects.create_user(bundle.data['uuid'],'1')
user.save()
except:
pass
return bundle
Run Code Online (Sandbox Code Playgroud) 请告诉我为什么这适用于MediaPLayer而不是videoView?以及如何使其与视频视图一起使用?
视频从API下载并保存在我创建的文件夹中:
File mediadir = cw.getDir("tvr", Context.MODE_PRIVATE);
Run Code Online (Sandbox Code Playgroud)
VideoView
final Uri uri = Uri.parse(path);
// path = /data/data/com.foo.app/tvr/video.mp4
videoView = (VideoView) findViewById(R.id.videoView);
videoView.setVisibility(View.VISIBLE);
videoView.setOnCompletionListener(this);
videoView.setVideoURI(Uri.parse(path));
videoView.start();
Run Code Online (Sandbox Code Playgroud)
错误视频对不起,此视频不能是播放器和错误(1,-2 ......)
MediaPlayer ---这个工作
FileInputStream fileInputStream = new FileInputStream(path);
MediaPlayer pl = new MediaPlayer();
pl.setDataSource(fileInputStream.getFD());
pl.prepare();
pl.start();
Run Code Online (Sandbox Code Playgroud) 嗨,我刚开始玩Mongoose.看起来真棒!
现在来自Django背景,如何实现一种类型的选项字段,如:
STATUS_OPTIONS : [{"Open",1},{"Closed",2},{"Pending",3"}]
status: { type:String, required:true, options:STATUS_OPTIONS },
Run Code Online (Sandbox Code Playgroud)
因此它可以设置为status = Open或类似的东西.
或者这应该是一个普通的字符串字段,我在我的应用程序中相应地设置它?
我想生成 django 模板/视图的 PDF;使用模板标签等。
来自 django-wkhtmltopdf 的文档:
from django.conf.urls.defaults import url, patterns
from wkhtmltopdf.views import PDFTemplateView
urlpatterns = patterns('',
url(r'^pdf/$', PDFTemplateView.as_view(template_name='my_template.html',
filename='my_pdf.pdf'), name='pdf'),
)
Run Code Online (Sandbox Code Playgroud)
或者他们以你自己的观点说:
from wkhtmltopdf.views import PDFTemplateView
class MyPDF(PDFTemplateView):
filename = 'my_pdf.pdf'
template_name = 'my_template.html'
cmd_options = {
'margin-top': 3,
}
Run Code Online (Sandbox Code Playgroud)
如果这是我的观点:
def download_report(request):
vends = Vends.objects.all()
return render(request, 'report_template.html', {'vends':vends})
Run Code Online (Sandbox Code Playgroud)
我将如何生成此视图渲染时的报告?不仅仅是模板,因为那样就没用了?
string = "$hahahaha$hahahaha hello";
Run Code Online (Sandbox Code Playgroud)
我怎样才能删除 2 $ 和 $ 之间的所有内容,所以我最终得到:
hahahaha hello
Run Code Online (Sandbox Code Playgroud)
$ 也可以是“@”、“*”、“&”或“?”
我试图首先按名称排序此列表.然后,在第一组结果(其中flag ="ZAR")之后,我想按时间排序剩余的元素而不是反过来:
import operator
list = [
{"flag":"ZAR", "time":"17:45"},
{"flag":"AUS", "time":"17:30"},
{"flag":"AUS", "time":"17:15"},
{"flag":"USA", "time":"17:00"},
{"flag":"GBP", "time":"16:55"},
{"flag":"ZAR", "time":"16:45"},
{"flag":"USA", "time":"16:35"},
{"flag":"GBP", "time":"16:25"},
{"flag":"ZAR", "time":"16:15"},
]
list.sort(key=operator.itemgetter("time"))
list.sort(key=operator.itemgetter("flag"),reverse=True)
print list
[{'flag': 'ZAR', 'time': '16:15'}, {'flag': 'ZAR', 'time': '16:45'}, {'flag': 'ZAR', 'time': '17:45'}, {'flag': 'USA', 'time': '16:35'}, {'flag': 'USA', 'time': '17:00'}, {'flag': 'GBP', 'time': '16:25'}, {'flag': 'GBP', 'time': '16:55'}, {'flag': 'AUS', 'time': '17:15'}, {'flag': 'AUS', 'time': '17:30'}]
Run Code Online (Sandbox Code Playgroud)
如您所见,标记排序已正确完成,但其他元素仅按排序国家/地区的时间排序.
我想要的是始终拥有ZAR,之后标志名称是什么,只有时间.所以它应该给出这个结果:
[{'flag': 'ZAR', 'time': '16:15'}, {'flag': 'ZAR', 'time': '16:45'}, {'flag': 'ZAR', 'time': '17:45'}, …Run Code Online (Sandbox Code Playgroud) 我有一个文本文件的例子:(我不知道你叫什么,一棵树?)
key1
subkey1
subkey2
choice1
key2
subkey1
subkey2
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像这样:
[
{
"text":"key1",
"children":[
{
"text":"subkey1",
children:[]
},
{
"text":"subkey2",
children:[
{
"text":"choice1",
"children":[]
}
]
},
]
},
{
"text":"key2",
"children":[
{
"text":"subkey1",
children:[]
},
{
"text":"subkey2",
children:[]
},
]
}
]
Run Code Online (Sandbox Code Playgroud)
这就是我正在做的事情,我不明白你如何将子元素带入父元素,这应该能够无限深入.
import itertools
def r(f, depth, parent, l, children):
for line in f:
line = line.rstrip()
newDepth = sum(1 for i in itertools.takewhile(lambda c: c=='\t', line))
node = line.strip()
if parent is not None:
print parent, children
children …Run Code Online (Sandbox Code Playgroud) 我有一个保存游览的模型.用户可以改变这次短途旅行,但我需要知道这次短途旅行之前的变化,因为我会记录每次短途旅行的"预订"次数,如果你改变了短途旅行,我需要删除一次预订.以前的游览.
我不完全确定应该怎么做.
我猜你用这个信号了吗?
我应该使用pre_save,pre_init还是最好用的?
pre_save看起来不正确,因为它打印新值,而不是我预期的"旧值"
@receiver(pre_save, sender=Delegate)
def my_callback(sender, instance, *args, **kwargs):
print instance.excursion
Run Code Online (Sandbox Code Playgroud)