小编Jos*_*iah的帖子

PHP从文件中读写JSON

我在文件中有以下JSON list.txt:

{
"bgates":{"first":"Bill","last":"Gates"},
"sjobs":{"first":"Steve","last":"Jobs"}
}
Run Code Online (Sandbox Code Playgroud)

如何"bross":{"first":"Bob","last":"Ross"}使用PHP 添加到我的文件?

这是我到目前为止所拥有的:

<?php

$user = "bross";
$first = "Bob";
$last = "Ross";

$file = "list.txt";

$json = json_decode(file_get_contents($file));

$json[$user] = array("first" => $first, "last" => $last);

file_put_contents($file, json_encode($json));

?>
Run Code Online (Sandbox Code Playgroud)

这给了我一个致命错误:不能在这一行使用stdClass类型的对象作为数组:

$json[$user] = array("first" => $first, "last" => $last);
Run Code Online (Sandbox Code Playgroud)

我正在使用PHP5.2.有什么想法吗?谢谢!

php json

44
推荐指数
4
解决办法
12万
查看次数

IE7/IE8中的Javascript JSON日期解析返回NaN

我正在从JSON事件源解析日期 - 但日期在IE7/8中显示"NaN":

// Variable from JSON feed (using JQuery's $.getJSON)
var start_time = '2012-06-24T17:00:00-07:00';

// How I'm currently extracting the Month & Day
var d = new Date(start_time);
var month = d.getMonth();
var day = d.getDate();

document.write(month+'/'+day);// "6/24" in most browsers, "Nan/Nan" in IE7/8
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?谢谢!

javascript date utc internet-explorer-8 internet-explorer-7

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

嵌套JSON:如何将新项添加(推送)到对象?

我刚开始使用Arrays,Objects和JSON - 所以希望我能在这里看到一些简单的东西.我在尝试新项目添加(推送)到我的json对象时遇到错误.

我遇到以下错误:( Result of expression 'library.push' [undefined] is not a function 在我的代码片段的底部).

// This is my JSON object generated from a database
var library = {
    "Gold Rush" : {
        "foregrounds" : ["Slide 1","Slide 2","Slide 3"],
        "backgrounds" : ["1.jpg","","2.jpg"]
    },
    "California" : {
        "foregrounds" : ["Slide 1","Slide 2","Slide 3"],
        "backgrounds" : ["3.jpg","4.jpg","5.jpg"]
    }
}

// These will be dynamically generated vars from editor
var title = "Gold Rush";
var foregrounds = ["Howdy","Slide 2"]; …
Run Code Online (Sandbox Code Playgroud)

javascript jquery json

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

HTML5音频:如何只播放音频文件的选定部分(音频精灵)?

我正在开发iOS节拍器网络应用程序.由于移动safari一次只能播放一个声音,我正在尝试创建一个"音频精灵" - 我可以使用单个音轨的不同片段来生成不同的声音.我有1秒的剪辑,上面有2个半秒的声音.

<audio id="sample" src="sounds.mp3"></audio>

<a href="javascript:play1();">Play1</a>
<a href="javascript:play2();">Play2</a>
<a href="javascript:pauseAudio();">Pause</a>

<script>
var audio = document.getElementById('click');

function play1(){
    audio.currentTime = 0;
    audio.play();

    // This is the problem area
    audio.addEventListener('timeupdate', function (){
        if (currentTime >= 0.5) {
            audio.pause();
        }
    }, false);
}   

function play2(){
    audio.currentTime = 0.5;
    audio.play();
}

function pause(){
    audio.pause();
}
</script>
Run Code Online (Sandbox Code Playgroud)

JSFiddle上看到它.

正如您所看到的,我试图使用'timeupdate'事件(jPlayer示例)但无济于事.

我见过Remy Sharp关于音频精灵的帖子,但是(A)我无法让它为我工作,而且(B)我宁愿远离库依赖.

有任何想法吗?在此先感谢您的帮助!


更新

我现在使用它setInterval:

function play1(){
    audio.currentTime = 0;
    audio.play();
    int = setInterval(function() …
Run Code Online (Sandbox Code Playgroud)

javascript html5 javascript-events html5-audio

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

如何在MacGap中打印HTML元素的内容?

我正在使用MacGap2创建一个WebView应用程序,我希望能够打印HTML元素的内容(具有在Safari/Preview /等中看到的打印预览).

我一直在关注WebUIDelegate的webView:printFrameView以及在Cocoa中打印WebView的整个内容,而不仅仅是显示 - 但我很难将它们放在一起,因为我是Objective-C/Cocoa的新手.

如果我想要这样的方法(如果打印预览有效,则不需要选项):

MacGap.print([HTMLelement], [options]);

// Example usage
var el = document.getElementById('view');

// Or if not element, send as HTML string? (with inline CSS)
// el = el.innerHTML;

MacGap.print(el, { printBackgrounds: true, landscape: false });
Run Code Online (Sandbox Code Playgroud)

我需要添加到我的MacGap类/命令中?

App.h:

- (void) print:(NSString*)printString;
Run Code Online (Sandbox Code Playgroud)

App.m:

- (void) print:(NSString*)printString {
    // ???
} 
Run Code Online (Sandbox Code Playgroud)

macos cocoa objective-c webview macgap

9
推荐指数
1
解决办法
256
查看次数

contentEditable + selectAll:Firefox不允许动态生成内容的键盘输入

我在Firefox中遇到问题(其他浏览器似乎工作正常),动态生成的元素包含一个contenteditable="true"属性:

如果我selectAll(动态地或用我的鼠标),Firefox将不允许键盘输入.

请参阅我的jsFiddle示例以供参考.这似乎只影响Firefox.

$(document).ready(function(){
$('.edit').live('dblclick', function () {
    document.execCommand('selectAll',false,null);
});

$('#live').append('<p class="edit" contenteditable="true">This content is generated. Firefox will not allow keyboard input when "ALL" is selected.</p>');
});
Run Code Online (Sandbox Code Playgroud)

编辑: 这是我正在努力的实际应用程序(原谅尘埃):cr8.me/app/ff.html - 我想要的是单击(双击以选择所有文本)a Note,Category,或计划标题进行编辑.它适用于任何人吗?也许这只是我的配置 - 或者糟糕的脚本.第137,572行是相关的.

javascript firefox jquery selectall contenteditable

7
推荐指数
1
解决办法
1901
查看次数

使用IPP for Node JS时打印作业延迟

我正在使用Node JS的IPP(和CUPS)从我们的儿童登记系统打印标签(DYMO Labelwriter 450 Turbo).我需要打印qty每个标签的不同数量(var ),具体取决于孩子在哪个房间(1-3).目前我正在为每个标签创建一个新的IPP打印作业 - 但打印之间有几秒钟的延迟.

有没有办法将数量传递给每个作业的IPP以消除延迟?或者可能将多个相同的.pdf传递到一个作业中?

Vars pdf(生成的标签 - 使用.pdf模板),qty(需要打印的标签数量)和pid(要打印的打印机的打印机ID)传递给下面的代码:

function print(qty, pid, first, last, gender, room, notes, notesr, timestamp, age, grade, code) {

    fs.readFile('label.pdf', 'utf-8', function (err, pdf) {

        pdf = pdf.toString();
        pdf = pdf.replace('<FIRST>', first).replace('<LAST>', last).replace('<GENDER>', gender).replace('<ROOM>', room).replace('<NOTES>', notes).replace('<NOTESON>', notesr).replace('<TIMESTAMP>', timestamp).replace('<AGE>', age).replace('<GRADE>', grade).replace('<CODE>', code);

        if (err)
            throw err;

        var printer = ipp.Printer('http://127.0.0.1:631/printers/DYMO_'+pid);
        var file = {
            'operation-attributes-tag':{
                'requesting-user-name': 'Test User',
                'job-name': 'My …
Run Code Online (Sandbox Code Playgroud)

javascript printing pdf node.js

5
推荐指数
1
解决办法
1891
查看次数

如何使用带有节点js的pdfkit管道流

在PDFkit 0.5之前 - 以下对我有用(通过pdfkit生成pdf /通过ipp打印到CUPS):

var ipp = require("ipp");
var PDFDocument = require("pdfkit");

var doc = new PDFDocument;
doc.text("Hello World");

doc.output(function(pdf)){
    var printer = ipp.Printer("http://127.0.0.1:631/printers/1");
    var file = {
        "operation-attributes-tag":{
            "requesting-user-name": "User",
        "job-name": "Print Job",
        "document-format": "application/pdf"
        },
        data: new Buffer(pdf, "binary")
    };

    printer.execute("Print-Job", file, function (err, res) {
        console.log("Printed: "+res.statusCode);
    });
}
Run Code Online (Sandbox Code Playgroud)

从PDFkit 0.5开始 - 该output方法已被弃用 - 但我似乎无法找到在pipe我的场景中使用新方法的示例.如果我没有使用浏览器,我还需要像blob-stream这样的模块吗?

node.js node-pdfkit

5
推荐指数
1
解决办法
8817
查看次数

Firefox syntax issue when placing an <li> inside of an <a> - not linkable?

我有一个css sprite导航栏,其中li被包装在一个用于链接的href标签中...

<div id="header">
    <ul>
        <a href="/"><li id="supplements-link"></li></a>
        <a href="/tutorials/"><li id="tutorials-link"></li></a>
        <a href="/blog/"><li id="blog-link"></li></a>
    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

在Safari,Chrome,Opera和IE中它对我来说很好用 - 但链接在Firefox中不活跃,当我查看Firebug中的代码时,Firefox会将href和li标记呈现为单独的行:

<div id="header">
    <ul>
        <li id="supplements-link"></li>
        <a href="/"></a>
        <li id="tutorials-link"></li>
        <a href="/tutorials/"></a>
        <li id="blog-link"></li>
        <a href="/blog/"></a>
    </ul>
</div>
Run Code Online (Sandbox Code Playgroud)

有小费吗?谢谢!

html css firefox

0
推荐指数
1
解决办法
644
查看次数