2
我已經創建了我的圖書館,像這樣:如何在聚合物中使用自定義Dart庫?
// web/com/jessewarden/workoutlogger/workoutloggerlib.dart
library workoutloggerlib;
import 'dart:async';
import 'dart:html';
import 'package:polymer/polymer.dart';
part "types/WorkoutTypes.dart";
part "vo/Exercise.dart";
part "vo/Set.dart";
part "vo/Workout.dart";
part "views/SetView.dart";
part "views/SetView.html";
我SetView.dart:
part of workoutloggerlib;
@CustomTag('set-view')
class SetView extends PolymerElement
{
@published
Set set;
SetView.created() : super.created();
}
及其相關的HTML:
<polymer-element name="set-vew" attributes="count">
<template>
<div>
<h3>{{set.name}}</h3>
<span class="label label-primary">Goal</span>
<div class="input-group">
<span class="input-group-addon">Reps</span>
<input type="text" class="form-control disabled" value={{set.goalReps}}>
</div>
<div class="input-group">
<span class="input-group-addon">Weight</span>
<input type="text" class="form-control" value="{{set.goalWeight}}">
<span class="input-group-addon">lbs</span>
</div>
</div>
</template>
<script type="application/dart" src="SetView.dart"></script>
</polymer-element>
然而,當她編譯,運行時我得到:
'http://somelocalserver/WorkoutLogger/web/com/jessewarden/workoutlogger/views/SetView.dart': error: line 1 pos 6: url expected
part of workoutloggerlib;
^: http://somelocalserver/WorkoutLogger/web/com/jessewarden/workoutlogger/views/SetView.dart
Internal error: 'http://somelocalserver/WorkoutLogger/web/com/jessewarden/workoutlogger/views/SetView.dart': error: line 1 pos 6: url expected
part of workoutloggerlib;
^
Internal error: 'http://somelocalserver/WorkoutLogger/web/com/jessewarden/workoutlogger/views/SetView.dart': error: line 1 pos 6: url expected
part of workoutloggerlib;
^
如果我手動爲每個文件導入類,放棄我的庫,它可以正常工作。很明顯,這是不期望的,因爲代碼不可管理,擁有更緊密的依賴關係,並且很難重構。
這聽起來像我得讓我的聚合物「意見」分開我的核心代碼,因爲我共享大量的課程,而且不能在每一個班級重複進口,這實在太笨拙了。 Nick Floros在Google+上建議我查看https://github.com/sethladd/dart-polymer-dart-examples中的示例,這些示例有許多使用庫的聚合物小型應用程序。嘗試... – JesterXL
您可以創建一個庫文件,導出其他幾個庫,如我在這裏[聚合物元素.dart](https://github.com/ErikGrimes/polymer_elements/blob/master/lib/polymer_elements.dart)和導入此庫而不是此文件中列出的每個庫。 –
如果我更改了SetView.html中的第一行: workoutloggerlib的一部分; 至: import'package:polymer/polymer.dart'; import'../workoutloggerlib.dart'; 然後它工作。注意,即使它包含在我的庫中,我仍然必須導入polymer.dart文件。我還必須從庫中刪除所有聚合物飛鏢和html相關類。不知道爲什麼我必須再次輸入聚合物類,但至少我所有的聚合物鏢文件現在只有2個進口,這很好。 – JesterXL