小编Sha*_*awn的帖子

json解析错误语法错误意外结束输入

我得到了以下代码

function pushJsonData(productName) {
    $.ajax({
        url: "/knockout/SaveProduct",
        type: "POST",
        contentType: "application/json",
        dataType: "json",
        data: " { \"Name\" : \"AA\" } ",
        async: false,
        success: function () {
            loadJsonData();   
        },
        error: function (jqXHR, textStatus, errorThrown) {
          alert(textStatus + " in pushJsonData: " + errorThrown + " " + jqXHR);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

请注意,我对数据值进行了硬编码.数据很好地推送到数据库中.但是,我不断收到错误"解析错误语法错误意外结束输入".我确信我的数据是正确的JSON语法.当我在Chrome of Chrome检查器上查看时,saveProduct请求显示数据是正确的.

{ "Name": "AA" }
Run Code Online (Sandbox Code Playgroud)

此POST请求没有响应.所以我对解析错误的来源毫无头绪.我尝试过使用FireFox浏览器.同样的事情发生了.

任何人都可以对错误提出一些看法吗?

谢谢,

PS这是控制器代码

namespace MvcApplJSON.Controllers
{
    public class KnockoutController : Controller
    {
        //
        // GET: /Knockout/

        public ActionResult Index()
        {
            return …
Run Code Online (Sandbox Code Playgroud)

ajax jquery json asp.net-mvc-4 knockout.js

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

当窗口最大化时,如何使所有控件按比例调整大小?

当我单击最大化按钮时,窗口最大化但控件未按比例调整大小.使控件调整大小的最佳方法是什么?我正在使用MVVM.

这是我的代码.

<Window x:Class="DataTransfer.View.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Icon="/DataTransfer;component/View/Images/ms_msnexplore.gif"

        ResizeMode="CanResizeWithGrip"
        Title="Window1" Height="500" Width="600">
    <!--Style="{DynamicResource OfficeStyle}"-->
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <!--<ResourceDictionary Source="/DataTransfer;component/View/WindowBase.xaml" />-->
                <!--<ResourceDictionary Source="/DataTransfer;component/Themes/WPFThemes/CalendarResource.xaml" />-->
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Window.Resources>

    <Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width ="*" />
    </Grid.ColumnDefinitions>
        <Button Content="Button" HorizontalAlignment="Left" Margin="52,28,0,0" VerticalAlignment="Top" Width="75" Height="22" />
        <DatePicker Name="dp" HorizontalAlignment="Left" Margin="175,25,0,0" VerticalAlignment="Top" Width="123" Text="aaa" GotFocus="DateGotFocused" LostFocus="OnLeaveArchiveDate"/>
        <Calendar HorizontalAlignment="Left" Margin="47,162,0,0" VerticalAlignment="Top"/>
        <TextBox Name="t1" HorizontalAlignment="Left" Height="23" Margin="337,23,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120" LostFocus="LeaveField" />
        <RadioButton Content="RadioButton" HorizontalAlignment="Left" Margin="88,92,0,0" VerticalAlignment="Top"/>
        <CheckBox Content="CheckBox" HorizontalAlignment="Left" Margin="252,96,0,0" VerticalAlignment="Top"/>
        <ComboBox …
Run Code Online (Sandbox Code Playgroud)

wpf mvvm c#-4.0

39
推荐指数
1
解决办法
13万
查看次数

Angular 2 + Typescript编译器复制html和css文件

在Angular2中我会有

"outDir": "dist/app"
Run Code Online (Sandbox Code Playgroud)

在tsconfig.json中.因此,转换后的.js和.map文件将在/ dist/app /文件夹和/或其子文件夹中生成.这一切都很好.

在我的components.ts文件中,我也使用了像这样引用的html和css

@Component({
  selector: 'my-app', 
  templateUrl: 'app/appshell/app.component.html',
  styleUrls: ['app/appshell/app.component.css'],
  ......
}
Run Code Online (Sandbox Code Playgroud)

有没有办法让编译器也复制整个项目的引用的html和css文件?如果是,我将如何配置我的tsconfig.json?

我查看了https://www.typescriptlang.org/docs/handbook/compiler-options.html中的编译器选项,但没有找到有关复制html/css文件的任何信息.

更新: 我的文件夹结构是这样的

Root
  |--app       // for ts
  |--dist/app  // for js
Run Code Online (Sandbox Code Playgroud)

tsconfig.json

"outDir": "dist/app"
Run Code Online (Sandbox Code Playgroud)

的package.json

{
  "name": "TestApp",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "html": "find ./app -name '*.html' -type f -exec cp --parents {} ./dist \\;",
    ......
}
Run Code Online (Sandbox Code Playgroud)

它不会复制html文件.但是没有错误.

再次更新:

对于那些使用Linux操作系统的人来说,Bernardo的解决方案是一个有效的解决方案.对于那些使用Windows操作系统的用户,以下应该可以使用.

  "scripts": {
    "html": "XCOPY /S /y .\\app\\*.html .\\dist\\app" }
Run Code Online (Sandbox Code Playgroud)

typescript angular

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

异步管道不会将对象数据填充到模板中

任何人都可以帮我看看我的模板中是否存在语法错误?它不会给出错误,但不会将数据填入模板:

<div *ngIf="(hero | async)">
  <h2>{{hero}}</h2>
  <h2>{{hero.name}} details!</h2>
  <div>
    <label>_id: </label>{{hero._id}}</div>
  <div>
    <label>name: </label>
    <input [(ngModel)]="hero.name" placeholder="name" />
  </div>
  <button (click)="goBack()">Back</button>
</div>
Run Code Online (Sandbox Code Playgroud)

组件代码

export class HeroDetailComponent implements OnInit {
    errorMessage: string;

    //@Input() 
    hero: Observable<Hero>;

    constructor(
        private _heroService: HeroService,
        private _routeParams: RouteParams) {
    }

    ngOnInit() {
        let _id = +this._routeParams.get('_id');
        this._heroService.loadHero(_id);
        this.hero = this._heroService.hero$;
        this.hero.subscribe(data => 
           console.log(data)
        )
    }
Run Code Online (Sandbox Code Playgroud)

console.log(data)打印:

对象{_id:11,名称:"尼斯先生"}

这意味着正确检索数据.

<div>块也显示出来,这意味着*ngIf该对象看起来是非空的.

<h2>{{hero}}</h2>节目[object Object].

但为什么{{hero.name}}不显示?

angular2-template angular

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

AWS Glue需要很长时间才能完成

我只是按如下方式完成一项非常简单的工作

glueContext = GlueContext(SparkContext.getOrCreate())
l_table = glueContext.create_dynamic_frame.from_catalog(
             database="gluecatalog",
             table_name="fctable") 
l_table = l_table.drop_fields(['seq','partition_0','partition_1','partition_2','partition_3']).rename_field('tbl_code','table_code')
print "Count: ", l_table.count()
l_table.printSchema()
l_table.select_fields(['trans_time']).toDF().distinct().show()
dfc = l_table.relationalize("table_root", "s3://my-bucket/temp/")
print "Before keys() call "
dfc.keys()
print "After keys() call "
l_table.select_fields('table').printSchema()
dfc.select('table_root_table').toDF().where("id = 1 or id = 2").orderBy(['id','index']).show()
dfc.select('table_root').toDF().where("table = 1 or table = 2").show()
Run Code Online (Sandbox Code Playgroud)

数据结构也很简单

root
|-- table: array
| |-- element: struct
| | |-- trans_time: string
| | |-- seq: null
| | |-- operation: string
| | |-- order_date: string
| | |-- …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services aws-glue

11
推荐指数
2
解决办法
5184
查看次数

WPF动态更改资源文件和主题

我的项目在整个项目中为所有WPF窗口使用ProjectTheme.xaml文件.ProjectTheme.xaml文件引用样式主题,如下所示

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <ResourceDictionary.MergedDictionaries>
        <!-- In order to modify the project's theme, change this line -->
        <ResourceDictionary Source="/MyProject;component/Themes/WPFThemes/Customized.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

所有WPF Windows引用WindowBase.xaml

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/MyProject;component/View/WindowBase.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)

WindowBase.xaml引用自定义标题栏Bar1.xaml

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/MyProject;component/Themes/WPFThemes/Bar1.xaml" />
</ResourceDictionary.MergedDictionaries>
Run Code Online (Sandbox Code Playgroud)

Bar1.xaml引用了ProjectTheme.xaml

<ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="/MyProject;component/ProjectTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
Run Code Online (Sandbox Code Playgroud)

所以heriarchy是

  • Window1引用WindowBase.xaml
  • WindowBase引用Bar1.xaml
  • Bar1引用了ProjectTheme.xaml
  • ProjectTheme.xaml引用真实的主题资源文件.

这很好用.现在我想在运行时动态更改项目主题而不退出应用程序.假设我有几个主题样式文件

  • Customized.xaml
  • Customized1.xaml
  • Customized2.xaml

我的问题是,是否可以在运行时动态更新ProjectTheme.xaml文件以更改行

<ResourceDictionary Source="/MyProject;component/Themes/WPFThemes/Customized.xaml" />
Run Code Online (Sandbox Code Playgroud)

<ResourceDictionary Source="/MyProject;component/Themes/WPFThemes/Customized1.xaml" />
Run Code Online (Sandbox Code Playgroud)

实现我的目标?如果是,我该怎么办?如果不是,原因是什么,以及实现目标的最佳(其他)方式是什么?

我尝试了以下但没有一个工作:风格不会改变.

方式1

Application.Current.Resources.MergedDictionaries.Clear();
Uri NewTheme = new Uri(@"/MyProject;component/Themes/WPFThemes/Customized2.xaml", UriKind.Relative);
ResourceDictionary dictionary = (ResourceDictionary)Application.LoadComponent(NewTheme);
Application.Current.Resources.MergedDictionaries.Add(dictionary);
Run Code Online (Sandbox Code Playgroud)

方式2

Application.Current.Resources.MergedDictionaries.RemoveAt(0);
Uri NewTheme = …
Run Code Online (Sandbox Code Playgroud)

wpf mvvm c#-4.0

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

Oracle.ManagedDataAccess.dll中的OracleBulkCopy类?

我正在使用OracleBulkCopy类来引用Oracle.DataAccess.dll.我想使用Oracle.ManagedDataAccess.dll来轻松部署.但后来我遇到了构建错误"找不到OracleBulkCopy"

有谁知道为什么OracleBulkCopy不包含在Oracle.ManagedDataAccess.dll中?

c# oracle odp.net c#-4.0

10
推荐指数
2
解决办法
7812
查看次数

Angular2 RC1子路由已定义但未被识别

曾经用于beta/...的工作已不再适用.使用新的新RC1路由器,我该如何进行子路由?

文件夹结构

app
  |--home/
  |    |--home.component.ts
  |--login/
  |    |--login.ts
  |--appShell/
  |    |--app.component.ts
  |--apps/
       |--hero/
            |--hero-shell.component.ts  
            |--horees.component.ts 
            |--hero-detail.component.ts
Run Code Online (Sandbox Code Playgroud)

计划的导航是

app.component -> home.component -> heroshell.component -> heroes.component 
Run Code Online (Sandbox Code Playgroud)

app.component.ts路线

@Routes([
    { path: '/heroshell', component: HeroShellComponent },
    { path: '/home',  component: HomeComponent },
    { path: '/login', component: Login },   
])
export class AppComponent implements OnInit {
  title = 'Apps';       
  constructor(public _auth: Authentication, 
              public router: Router,
              private _dialogService: DialogService
              ) {}      
  ngOnInit() {
    this.router.navigate(['/login']);
  }
  .......
Run Code Online (Sandbox Code Playgroud)

登录成功后,Login类将会

this.router.navigate(['/home']);
Run Code Online (Sandbox Code Playgroud)

从HomeComponent.ts我可以做到

this.router.navigate(['/heroshell']);
Run Code Online (Sandbox Code Playgroud)

到目前为止这么好,没问题.在hero-shell.component.ts中我有子路由

@Component({
  selector: 'my-app1', 
  templateUrl: …
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

8
推荐指数
1
解决办法
3071
查看次数

Angular 4与React混合

我们正在评估为我们的企业Web应用程序选择哪个前端框架.目前的选择是Angular 4和React.

我看到有人把这两个混在一起https://github.com/jesion/angular2-react

我的问题如下:

  1. 将Angular 4与React混合是一个好主意吗?这样做的优点和缺点是什么?
  2. 将React用作视图模板并使其成为Angular组件"templateUrl"有什么性能优势?

reactjs angular

8
推荐指数
1
解决办法
5374
查看次数

单独一个线程上的javascript回调函数

Javascript是单线程的.那么回调函数和它的包含函数是否在与主循环/事件循环相同的线程上执行?

database.query("SELECT * FROM hugetable", function(rows) {  // anonymous callback function
   var result = rows;
   console.log(result.length);
});
console.log("I am going without waiting...");
Run Code Online (Sandbox Code Playgroud)

如果query()方法及其回调函数在与事件循环相同的线程上执行,则会发生阻塞.如果不是为什么Javascript被称为单线程?

任何人都可以帮助验证javascript(browser/node.js)是否在场景后面使用多个线程以实现非阻塞?

谢谢,

朋友们,我看到了你的意见和答案.对不起,我对javascript很新.我很困惑,单线程asyn调用不会阻塞.如果有100个用户从hugeTable请求数据,这可能每个并发一分钟,并且事件循环将这些任务分配到一个队列并依次执行它们,query()方法执行如何不阻止事件循环,因为它们全部打开一个单线程?

布拉德回答了这一部分

javascript jquery multithreading javascript-events

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