我想将html输入文件转换为json字符串,如下所示:
var jsonString = JSON.stringify(file);
console.log( file );
console.log( jsonString );
Run Code Online (Sandbox Code Playgroud)
现在,在我的萤火虫中:
File { size=360195, type="image/jpeg", name="xyz.jpg", mehr...}
Object {}
Run Code Online (Sandbox Code Playgroud)
为什么jsonString空?
背景信息:我想用jsonp将文件引用发送到另一个php服务器
附加信息:我想只将文件指针(引用)转换为字符串,通过GET发送.
简化,我正在做的是在控制台中运行它:
window.onbeforeunload = function (e) {
console.log(e);
}
Run Code Online (Sandbox Code Playgroud)
但是在控制台中,当事件触发时(通过在写一个SO问题的过程中试图"离开页面")我看到的是:
Event {clipboardData: undefined, cancelBubble: false, returnValue: true, srcElement: document, defaultPrevented: false…}
Run Code Online (Sandbox Code Playgroud)
旁边有一个小"i"图形.当我单击它旁边的箭头以在控制台中展开对象时,没有任何反应.箭头指示它已展开,但不会展开.
我在这里失踪了什么?
我正在尝试研究jquery类,但是我很难调试一个对象,因为我看不到它里面的元素
$("#birds").autocomplete({
source: "search.php",
select: function(event, ui) {
alert(ui);
}
});
Run Code Online (Sandbox Code Playgroud)
它返回[object Object] .. :(我的问题是如何提醒对象以便我可以看到该元素?
我有一个对象对象,我想遍历这些对象并在浏览器中显示它们;我有以下代码,但它只显示我 [object Object][object Object][object Object]; 如何显示实际对象?
my my_obj looks like:
{
"User": {
"description": "A user."
},
"Media": {
"description": "A media ."
}
}
var output = "";
for (var key in my_obj) {
output += my_obj[key];
}
response.send(output);
Run Code Online (Sandbox Code Playgroud)
谢谢
下面代码中的替换器在控制台上写入当前处理的字段名称
let a = { a1: 1, a2:1 }
let b = { b1: 2, b2: [1,a] }
let c = { c1: 3, c2: b }
let s = JSON.stringify(c, function (field,value) {
console.log(field); // full path... ???
return value;
});Run Code Online (Sandbox Code Playgroud)
但是我想在替换函数中获得字段的完整“路径”(不仅仅是它的名称) - 像这样
c1
c2
c2.b1
c2.b2
c2.b2[0]
c2.b2[1]
c2.b2[1].a1
c2.b2[1].a2
Run Code Online (Sandbox Code Playgroud)
怎么做?
我在<p>标签中的tinymce编辑器中有一些文本,没有别的,没有类,没有样式.当我选择文本并单击无序列表按钮,然后<p>成为一个列表.但每个<li>看起来像这样:
<li><span style="font-size: 12px; line-height: 1.5em;">Some text...</span></li>
这些样式来自哪里,哪个tinymce配置选项,哪个文件,哪个是什么??? 我希望列表按钮只添加列表html标签,没有任何跨度和样式.
这是我的tinymce配置.配置是直接从Chrome检查器复制的(这就是嵌套道具中没有缩进的原因):(断点位于第13547行,tinymce.add(t);在tiny_mce_src.js 中的语句处)
settings: Object
accessibility_focus: true
accessibility_warnings: false
add_form_submit_trigger: true
add_unload_trigger: true
apply_source_formatting: 0
bodyClass: "wysiwygeditor"
button_tile_map: true
content_css: "/sites/all/themes/adaptivetheme/at_core/css/at.layout.css,/sites/all/themes/atsl/css/global.base.css,/sites/all/themes/mytheme/css/global.styles.css
convert_fonts_to_spans: 1
convert_urls: false
delta_height: 0
delta_width: 0
dialog_type: "modal"
directionality: "ltr"
doctype: "<!DOCTYPE>"
document_base_url: "/"
entities: "quot,apos,amp,lt,gt,nbsp,iexcl"
entity_encoding: "named"
extended_valid_elements: ""
fix_table_elements: true
font_size_legacy_values: "xx-small,small,medium,large,x-large,xx-large,300%"
font_size_style_values: "xx-small,x-small,small,medium,large,x-large,xx-large"
forced_root_block: "p"
formats: Object
hidden_input: true
id: "edit-body-und-0-value"
ie7_compat: true
indent: "simple"
indent_after: "p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,tfoot,tbody,tr,section,article,hgroup,aside,figure,option,optgroup,datalist"
indent_before: …Run Code Online (Sandbox Code Playgroud) 我试图按年龄对一系列记录进行冒泡,但我得到的只是:
[object Object],[object Object],[object Object]
如何让它显示记录的值?
students = [
{name: "timothy", age: "9"},
{name: "claire", age: "12"},
{name: "michael", age: "20"}
];
for (var i = 0; i < students.length; i++) {
for (var j = i + 1; j < students.length; j++) {
if (Number(students[i].age) > Number(students[j].age)) {
tempValue = students[j].age;
students[j].age = students[i].age;
students[i].age = tempValue;
}
}
}
alert(students);
Run Code Online (Sandbox Code Playgroud) 我的问题可能有一个非常简单的解决方法,但我对 javascript 很陌生,似乎找不到答案。脚本如下:
var proxyUrl = 'https://cors-anywhere.herokuapp.com/',
targetUrl = 'https://api.darksky.net/forecast/[key]/[latitude],[longitude]'
fetch(proxyUrl + targetUrl)
.then(blob => blob.json())
.then(data => {
console.log(data);
document.getElementById('weather').innerHTML = data;
})
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它时,<p>元素不会更改为数据本身,而是更改为“[object Object]”我做错了什么?任何帮助表示赞赏。
PS:targetUrl变量在参数所在位置有占位符,它不会按原样运行。
所以说我有这个:
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
var car1 = new Car("VW", "Bug", 2012);
var car2 = new Car("Toyota", "Prius", 2004);
document.write(car1.make, car1.model, car1.year);
document.write(car2.make, car2.mocel, car2.year);
Run Code Online (Sandbox Code Playgroud)
有没有一种更干净的方法来写出对象的所有属性/值?谢谢!
我在现有模型上运行 .find() 查询。我过去曾使用过此代码并且什么也没改变,但现在突然由于某种原因它不起作用。我在想 MongoDB 或 MongooseJS 已更新并且功能已更改。
var retrieve = function() {
Repo.find({}, function(err, docs) {
console.log(docs)
})
};
retrieve();
Run Code Online (Sandbox Code Playgroud)
返回
[
model {
'$__': InternalCache {
strictMode: true,
selected: {},
shardval: undefined,
saveError: undefined,
validationError: undefined,
adhocPaths: undefined,
removing: undefined,
inserting: undefined,
version: undefined,
getters: {},
_id: 5e02e91c908f0f086e737189,
populate: undefined,
populated: undefined,
wasPopulated: false,
scope: undefined,
activePaths: [StateMachine],
pathsToScopes: {},
ownerDocument: undefined,
fullPath: undefined,
emitter: [EventEmitter],
'$options': true
},
isNew: false,
errors: undefined,
_doc: {
__v: 0,
stars: 2, …Run Code Online (Sandbox Code Playgroud) 在JS中,如果我将字符串记录到控制台,则显示不正确?
console.log(uniqueProducts); //
console.log("uniqueProducts:"+uniqueProducts);
Run Code Online (Sandbox Code Playgroud)
结果
[ { country: 'Russia', launches: 32 },
{ country: 'US', launches: 23 },
{ country: 'China', launches: 16 } ]
uniqueProducts:[object Object],[object Object],[object Object]
map
Run Code Online (Sandbox Code Playgroud)
那么为什么显示[object Object]而不是值呢?就像更改类型并附加字符串一样吗?
我对节点和 mongo db 都非常陌生。我正在创建从节点到 Mongo 的连接并尝试 CRUD 操作。我的操作在 Operations.js 中定义,并且我从索引调用函数。
我面临的问题是当我打印回调参数时
coll.find({}).toarray()- 这就是我得到所需输出的结果
[
{
_id: 5ea4843b0f28320524d23f14,
name: 'Vadonut',
description: 'Test Vadonut'
},
]
Run Code Online (Sandbox Code Playgroud)
但是当我打印index.js 的结果(这是来自operation.js 中的函数回调的结果)时,我得到的输出为
[object Object]
Run Code Online (Sandbox Code Playgroud)
我可以得到这方面的帮助吗????
索引.js:
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
const dboper = require('./operations')
const url = "mongodb://localhost:27017/";
const dbname = "dishes";
MongoClient.connect(url,(err,client)=>{
assert.equal(err,null);
console.log("Connected correctly correct to the server");
const db =client.db(dbname);
dboper.insertdocument(db,{"name":"Vadonut","description":"Test Vadonut"},'dishes',(result)=>{
console.log('Insert Document:\n'+result);
dboper.finddocument(db,'dishes',(result)=>{
console.log("Found Documents :\n"+result);
})
})
Run Code Online (Sandbox Code Playgroud)
****操作.js****
const assert = require('assert');
exports.insertdocument = …Run Code Online (Sandbox Code Playgroud)